The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

184 lines
7.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_MENUBARMODEL_JUCEHEADER__
  19. #define __JUCE_MENUBARMODEL_JUCEHEADER__
  20. #include "juce_PopupMenu.h"
  21. //==============================================================================
  22. /**
  23. A class for controlling MenuBar components.
  24. This class is used to tell a MenuBar what menus to show, and to respond
  25. to a menu being selected.
  26. @see MenuBarModel::Listener, MenuBarComponent, PopupMenu
  27. */
  28. class JUCE_API MenuBarModel : private AsyncUpdater,
  29. private ApplicationCommandManagerListener
  30. {
  31. public:
  32. //==============================================================================
  33. MenuBarModel() noexcept;
  34. /** Destructor. */
  35. virtual ~MenuBarModel();
  36. //==============================================================================
  37. /** Call this when some of your menu items have changed.
  38. This method will cause a callback to any MenuBarListener objects that
  39. are registered with this model.
  40. If this model is displaying items from an ApplicationCommandManager, you
  41. can use the setApplicationCommandManagerToWatch() method to cause
  42. change messages to be sent automatically when the ApplicationCommandManager
  43. is changed.
  44. @see addListener, removeListener, MenuBarListener
  45. */
  46. void menuItemsChanged();
  47. /** Tells the menu bar to listen to the specified command manager, and to update
  48. itself when the commands change.
  49. This will also allow it to flash a menu name when a command from that menu
  50. is invoked using a keystroke.
  51. */
  52. void setApplicationCommandManagerToWatch (ApplicationCommandManager* manager) noexcept;
  53. //==============================================================================
  54. /** A class to receive callbacks when a MenuBarModel changes.
  55. @see MenuBarModel::addListener, MenuBarModel::removeListener, MenuBarModel::menuItemsChanged
  56. */
  57. class JUCE_API Listener
  58. {
  59. public:
  60. /** Destructor. */
  61. virtual ~Listener() {}
  62. //==============================================================================
  63. /** This callback is made when items are changed in the menu bar model.
  64. */
  65. virtual void menuBarItemsChanged (MenuBarModel* menuBarModel) = 0;
  66. /** This callback is made when an application command is invoked that
  67. is represented by one of the items in the menu bar model.
  68. */
  69. virtual void menuCommandInvoked (MenuBarModel* menuBarModel,
  70. const ApplicationCommandTarget::InvocationInfo& info) = 0;
  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. //==============================================================================
  100. #if JUCE_MAC || DOXYGEN
  101. /** MAC ONLY - Sets the model that is currently being shown as the main
  102. menu bar at the top of the screen on the Mac.
  103. You can pass 0 to stop the current model being displayed. Be careful
  104. not to delete a model while it is being used.
  105. An optional extra menu can be specified, containing items to add to the top of
  106. the apple menu. (Confusingly, the 'apple' menu isn't the one with a picture of
  107. an apple, it's the one next to it, with your application's name at the top
  108. and the services menu etc on it). When one of these items is selected, the
  109. menu bar model will be used to invoke it, and in the menuItemSelected() callback
  110. the topLevelMenuIndex parameter will be -1. If you pass in an extraAppleMenuItems
  111. object then newMenuBarModel must be non-null.
  112. */
  113. static void setMacMainMenu (MenuBarModel* newMenuBarModel,
  114. const PopupMenu* extraAppleMenuItems = nullptr);
  115. /** MAC ONLY - Returns the menu model that is currently being shown as
  116. the main menu bar.
  117. */
  118. static MenuBarModel* getMacMainMenu();
  119. /** MAC ONLY - Returns the menu that was last passed as the extraAppleMenuItems
  120. argument to setMacMainMenu(), or nullptr if none was specified.
  121. */
  122. static const PopupMenu* getMacExtraAppleItemsMenu();
  123. #endif
  124. //==============================================================================
  125. /** @internal */
  126. void applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info);
  127. /** @internal */
  128. void applicationCommandListChanged();
  129. /** @internal */
  130. void handleAsyncUpdate();
  131. private:
  132. ApplicationCommandManager* manager;
  133. ListenerList <Listener> listeners;
  134. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MenuBarModel);
  135. };
  136. /** This typedef is just for compatibility with old code - newer code should use the MenuBarModel::Listener class directly. */
  137. typedef MenuBarModel::Listener MenuBarModelListener;
  138. #endif // __JUCE_MENUBARMODEL_JUCEHEADER__