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.

juce_MenuBarModel.h 8.0KB

9 years ago
10 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI 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. virtual void menuBarItemsChanged (MenuBarModel* menuBarModel) = 0;
  63. /** This callback is made when an application command is invoked that
  64. is represented by one of the items in the menu bar model.
  65. */
  66. virtual void menuCommandInvoked (MenuBarModel* menuBarModel,
  67. const ApplicationCommandTarget::InvocationInfo& info) = 0;
  68. /** Called when the menu bar is first activated or when the user finished interacting
  69. with the menu bar. */
  70. virtual void menuBarActivated (MenuBarModel* menuBarModel, bool isActive);
  71. };
  72. /** Registers a listener for callbacks when the menu items in this model change.
  73. The listener object will get callbacks when this object's menuItemsChanged()
  74. method is called.
  75. @see removeListener
  76. */
  77. void addListener (Listener* listenerToAdd) noexcept;
  78. /** Removes a listener.
  79. @see addListener
  80. */
  81. void removeListener (Listener* listenerToRemove) noexcept;
  82. //==============================================================================
  83. /** This method must return a list of the names of the menus. */
  84. virtual StringArray getMenuBarNames() = 0;
  85. /** This should return the popup menu to display for a given top-level menu.
  86. @param topLevelMenuIndex the index of the top-level menu to show
  87. @param menuName the name of the top-level menu item to show
  88. */
  89. virtual PopupMenu getMenuForIndex (int topLevelMenuIndex,
  90. const String& menuName) = 0;
  91. /** This is called when a menu item has been clicked on.
  92. @param menuItemID the item ID of the PopupMenu item that was selected
  93. @param topLevelMenuIndex the index of the top-level menu from which the item was
  94. chosen (just in case you've used duplicate ID numbers
  95. on more than one of the popup menus)
  96. */
  97. virtual void menuItemSelected (int menuItemID,
  98. int topLevelMenuIndex) = 0;
  99. /** This is called when the user starts/stops navigating the maenu bar.
  100. @param isActive true when the user starts navigating the menu bar
  101. */
  102. virtual void menuBarActivated (bool isActive);
  103. //==============================================================================
  104. #if JUCE_MAC || DOXYGEN
  105. /** OSX ONLY - Sets the model that is currently being shown as the main
  106. menu bar at the top of the screen on the Mac.
  107. You can pass nullptr to stop the current model being displayed. Be careful
  108. not to delete a model while it is being used.
  109. An optional extra menu can be specified, containing items to add to the top of
  110. the apple menu. (Confusingly, the 'apple' menu isn't the one with a picture of
  111. an apple, it's the one next to it, with your application's name at the top
  112. and the services menu etc on it). When one of these items is selected, the
  113. menu bar model will be used to invoke it, and in the menuItemSelected() callback
  114. the topLevelMenuIndex parameter will be -1. If you pass in an extraAppleMenuItems
  115. object then newMenuBarModel must be non-null.
  116. If the recentItemsMenuName parameter is non-empty, then any sub-menus with this
  117. name will be replaced by OSX's special recent-files menu.
  118. */
  119. static void setMacMainMenu (MenuBarModel* newMenuBarModel,
  120. const PopupMenu* extraAppleMenuItems = nullptr,
  121. const String& recentItemsMenuName = String());
  122. /** OSX ONLY - Returns the menu model that is currently being shown as
  123. the main menu bar.
  124. */
  125. static MenuBarModel* getMacMainMenu();
  126. /** OSX ONLY - Returns the menu that was last passed as the extraAppleMenuItems
  127. argument to setMacMainMenu(), or nullptr if none was specified.
  128. */
  129. static const PopupMenu* getMacExtraAppleItemsMenu();
  130. #endif
  131. //==============================================================================
  132. /** @internal */
  133. void applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo&) override;
  134. /** @internal */
  135. void applicationCommandListChanged() override;
  136. /** @internal */
  137. void handleAsyncUpdate() override;
  138. /** @internal */
  139. void handleMenuBarActivate (bool isActive);
  140. private:
  141. ApplicationCommandManager* manager;
  142. ListenerList<Listener> listeners;
  143. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MenuBarModel)
  144. };
  145. /** This typedef is just for compatibility with old code - newer code should use the MenuBarModel::Listener class directly. */
  146. typedef MenuBarModel::Listener MenuBarModelListener;
  147. #endif // JUCE_MENUBARMODEL_H_INCLUDED