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.

111 lines
4.1KB

  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 component which lists all menu items and groups them into categories
  23. by their respective parent menus. This kind of component is often used
  24. for so-called "burger" menus in mobile apps.
  25. @see MenuBarModel
  26. @tags{GUI}
  27. */
  28. class BurgerMenuComponent : public Component,
  29. private ListBoxModel,
  30. private MenuBarModel::Listener
  31. {
  32. public:
  33. //==============================================================================
  34. /** Creates a burger menu component.
  35. @param model the model object to use to control this burger menu. You can
  36. set the parameter or pass nullptr into this if you like,
  37. and set the model later using the setModel() method.
  38. @see setModel
  39. */
  40. BurgerMenuComponent (MenuBarModel* model = nullptr);
  41. /** Destructor. */
  42. ~BurgerMenuComponent() override;
  43. //==============================================================================
  44. /** Changes the model object to use to control the burger menu.
  45. This can be a nullptr, in which case the bar will be empty. This object will not be
  46. owned by the BurgerMenuComponent so it is up to you to manage its lifetime.
  47. Don't delete the object that is passed-in while it's still being used by this MenuBar.
  48. Any submenus in your MenuBarModel will be recursively flattened and added to the
  49. top-level burger menu section.
  50. */
  51. void setModel (MenuBarModel* newModel);
  52. /** Returns the current burger menu model being used. */
  53. MenuBarModel* getModel() const noexcept;
  54. /** @internal */
  55. void lookAndFeelChanged() override;
  56. private:
  57. //==============================================================================
  58. struct Row
  59. {
  60. bool isMenuHeader;
  61. int topLevelMenuIndex;
  62. PopupMenu::Item item;
  63. };
  64. std::unique_ptr<AccessibilityHandler> createAccessibilityHandler() override;
  65. void refresh();
  66. void paint (Graphics&) override;
  67. int getNumRows() override;
  68. void paintListBoxItem (int, Graphics&, int, int, bool) override;
  69. void listBoxItemClicked (int, const MouseEvent&) override;
  70. Component* refreshComponentForRow (int, bool, Component*) override;
  71. void resized() override;
  72. void menuBarItemsChanged (MenuBarModel*) override;
  73. void menuCommandInvoked (MenuBarModel*, const ApplicationCommandTarget::InvocationInfo&) override;
  74. void mouseUp (const MouseEvent&) override;
  75. void handleCommandMessage (int) override;
  76. void addMenuBarItemsForMenu (PopupMenu&, int);
  77. static bool hasSubMenu (const PopupMenu::Item&);
  78. //==============================================================================
  79. MenuBarModel* model = nullptr;
  80. ListBox listBox {"BurgerMenuListBox", this};
  81. Array<Row> rows;
  82. int lastRowClicked = -1, inputSourceIndexOfLastClick = -1, topLevelIndexClicked = -1;
  83. //==============================================================================
  84. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BurgerMenuComponent)
  85. };
  86. } // namespace juce