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.

120 lines
4.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. namespace juce
  20. {
  21. //==============================================================================
  22. /**
  23. A menu bar component.
  24. @see MenuBarModel
  25. */
  26. class JUCE_API MenuBarComponent : public Component,
  27. private MenuBarModel::Listener,
  28. private Timer
  29. {
  30. public:
  31. //==============================================================================
  32. /** Creates a menu bar.
  33. @param model the model object to use to control this bar. You can
  34. pass omit the parameter or pass nullptr into this if you like,
  35. and set the model later using the setModel() method.
  36. */
  37. MenuBarComponent (MenuBarModel* model = nullptr);
  38. /** Destructor. */
  39. ~MenuBarComponent();
  40. //==============================================================================
  41. /** Changes the model object to use to control the bar.
  42. This can be a null pointer, in which case the bar will be empty. Don't delete the object
  43. that is passed-in while it's still being used by this MenuBar.
  44. */
  45. void setModel (MenuBarModel* newModel);
  46. /** Returns the current menu bar model being used. */
  47. MenuBarModel* getModel() const noexcept;
  48. //==============================================================================
  49. /** Pops up one of the menu items.
  50. This lets you manually open one of the menus - it could be triggered by a
  51. key shortcut, for example.
  52. */
  53. void showMenu (int menuIndex);
  54. //==============================================================================
  55. /** @internal */
  56. void paint (Graphics&) override;
  57. /** @internal */
  58. void resized() override;
  59. /** @internal */
  60. void mouseEnter (const MouseEvent&) override;
  61. /** @internal */
  62. void mouseExit (const MouseEvent&) override;
  63. /** @internal */
  64. void mouseDown (const MouseEvent&) override;
  65. /** @internal */
  66. void mouseDrag (const MouseEvent&) override;
  67. /** @internal */
  68. void mouseUp (const MouseEvent&) override;
  69. /** @internal */
  70. void mouseMove (const MouseEvent&) override;
  71. /** @internal */
  72. void handleCommandMessage (int commandId) override;
  73. /** @internal */
  74. bool keyPressed (const KeyPress&) override;
  75. /** @internal */
  76. void menuBarItemsChanged (MenuBarModel*) override;
  77. /** @internal */
  78. void menuCommandInvoked (MenuBarModel*, const ApplicationCommandTarget::InvocationInfo&) override;
  79. private:
  80. //==============================================================================
  81. MenuBarModel* model;
  82. StringArray menuNames;
  83. Array<int> xPositions;
  84. Point<int> lastMousePos;
  85. int itemUnderMouse, currentPopupIndex, topLevelIndexClicked;
  86. int getItemAt (Point<int>);
  87. void setItemUnderMouse (int index);
  88. void setOpenItem (int index);
  89. void updateItemUnderMouse (Point<int>);
  90. void timerCallback() override;
  91. void repaintMenuItem (int index);
  92. void menuDismissed (int topLevelIndex, int itemId);
  93. static void menuBarMenuDismissedCallback (int, MenuBarComponent*, int);
  94. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MenuBarComponent)
  95. };
  96. } // namespace juce