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.

121 lines
4.2KB

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