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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  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 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. //==============================================================================
  21. /**
  22. A menu bar component.
  23. @see MenuBarModel
  24. @tags{GUI}
  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() override;
  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. class AccessibleItemComponent;
  82. //==============================================================================
  83. std::unique_ptr<AccessibilityHandler> createAccessibilityHandler() override;
  84. void timerCallback() override;
  85. int getItemAt (Point<int>);
  86. void setItemUnderMouse (int);
  87. void setOpenItem (int);
  88. void updateItemUnderMouse (Point<int>);
  89. void repaintMenuItem (int);
  90. void menuDismissed (int, int);
  91. void updateItemComponents (const StringArray&);
  92. int indexOfItemComponent (AccessibleItemComponent*) const;
  93. //==============================================================================
  94. MenuBarModel* model = nullptr;
  95. std::vector<std::unique_ptr<AccessibleItemComponent>> itemComponents;
  96. Point<int> lastMousePos;
  97. int itemUnderMouse = -1, currentPopupIndex = -1, topLevelIndexClicked = 0;
  98. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MenuBarComponent)
  99. };
  100. } // namespace juce