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_MenuBarComponent.h 4.2KB

10 years ago
10 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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_MENUBARCOMPONENT_H_INCLUDED
  18. #define JUCE_MENUBARCOMPONENT_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. A menu bar component.
  22. @see MenuBarModel
  23. */
  24. class JUCE_API MenuBarComponent : public Component,
  25. private MenuBarModel::Listener,
  26. private Timer
  27. {
  28. public:
  29. //==============================================================================
  30. /** Creates a menu bar.
  31. @param model the model object to use to control this bar. You can
  32. pass nullptr into this if you like, and set the model
  33. later using the setModel() method
  34. */
  35. MenuBarComponent (MenuBarModel* model);
  36. /** Destructor. */
  37. ~MenuBarComponent();
  38. //==============================================================================
  39. /** Changes the model object to use to control the bar.
  40. This can be a null pointer, in which case the bar will be empty. Don't delete the object
  41. that is passed-in while it's still being used by this MenuBar.
  42. */
  43. void setModel (MenuBarModel* newModel);
  44. /** Returns the current menu bar model being used. */
  45. MenuBarModel* getModel() const noexcept;
  46. //==============================================================================
  47. /** Pops up one of the menu items.
  48. This lets you manually open one of the menus - it could be triggered by a
  49. key shortcut, for example.
  50. */
  51. void showMenu (int menuIndex);
  52. //==============================================================================
  53. /** @internal */
  54. void paint (Graphics&) override;
  55. /** @internal */
  56. void resized() override;
  57. /** @internal */
  58. void mouseEnter (const MouseEvent&) override;
  59. /** @internal */
  60. void mouseExit (const MouseEvent&) override;
  61. /** @internal */
  62. void mouseDown (const MouseEvent&) override;
  63. /** @internal */
  64. void mouseDrag (const MouseEvent&) override;
  65. /** @internal */
  66. void mouseUp (const MouseEvent&) override;
  67. /** @internal */
  68. void mouseMove (const MouseEvent&) override;
  69. /** @internal */
  70. void handleCommandMessage (int commandId) override;
  71. /** @internal */
  72. bool keyPressed (const KeyPress&) override;
  73. /** @internal */
  74. void menuBarItemsChanged (MenuBarModel*) override;
  75. /** @internal */
  76. void menuCommandInvoked (MenuBarModel*, const ApplicationCommandTarget::InvocationInfo&) override;
  77. private:
  78. //==============================================================================
  79. MenuBarModel* model;
  80. StringArray menuNames;
  81. Array<int> xPositions;
  82. Point<int> lastMousePos;
  83. int itemUnderMouse, currentPopupIndex, topLevelIndexClicked;
  84. int getItemAt (Point<int>);
  85. void setItemUnderMouse (int index);
  86. void setOpenItem (int index);
  87. void updateItemUnderMouse (Point<int>);
  88. void timerCallback() override;
  89. void repaintMenuItem (int index);
  90. void menuDismissed (int topLevelIndex, int itemId);
  91. static void menuBarMenuDismissedCallback (int, MenuBarComponent*, int);
  92. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MenuBarComponent)
  93. };
  94. #endif // JUCE_MENUBARCOMPONENT_H_INCLUDED