The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

122 lines
4.3KB

  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_JUCEHEADER__
  18. #define __JUCE_MENUBARCOMPONENT_JUCEHEADER__
  19. #include "juce_MenuBarModel.h"
  20. //==============================================================================
  21. /**
  22. A menu bar component.
  23. @see MenuBarModel
  24. */
  25. class JUCE_API MenuBarComponent : public Component,
  26. private MenuBarModel::Listener,
  27. private Timer
  28. {
  29. public:
  30. //==============================================================================
  31. /** Creates a menu bar.
  32. @param model the model object to use to control this bar. You can
  33. pass 0 into this if you like, and set the model later
  34. using the setModel() method
  35. */
  36. MenuBarComponent (MenuBarModel* model);
  37. /** Destructor. */
  38. ~MenuBarComponent();
  39. //==============================================================================
  40. /** Changes the model object to use to control the bar.
  41. This can be a null pointer, in which case the bar will be empty. Don't delete the object
  42. that is passed-in while it's still being used by this MenuBar.
  43. */
  44. void setModel (MenuBarModel* newModel);
  45. /** Returns the current menu bar model being used.
  46. */
  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. #endif // __JUCE_MENUBARCOMPONENT_JUCEHEADER__