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.

114 lines
3.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2020 - 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 this technical preview, this file is not subject to commercial licensing.
  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. MenuBarModel* model;
  77. StringArray menuNames;
  78. Array<int> xPositions;
  79. Point<int> lastMousePos;
  80. int itemUnderMouse, currentPopupIndex, topLevelIndexClicked;
  81. int getItemAt (Point<int>);
  82. void setItemUnderMouse (int index);
  83. void setOpenItem (int index);
  84. void updateItemUnderMouse (Point<int>);
  85. void timerCallback() override;
  86. void repaintMenuItem (int index);
  87. void menuDismissed (int topLevelIndex, int itemId);
  88. static void menuBarMenuDismissedCallback (int, MenuBarComponent*, int);
  89. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MenuBarComponent)
  90. };
  91. } // namespace juce