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.

224 lines
8.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  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 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #pragma once
  20. //==============================================================================
  21. /**
  22. A component with a TabbedButtonBar along one of its sides.
  23. This makes it easy to create a set of tabbed pages, just add a bunch of tabs
  24. with addTab(), and this will take care of showing the pages for you when the
  25. user clicks on a different tab.
  26. @see TabbedButtonBar
  27. */
  28. class JUCE_API TabbedComponent : public Component
  29. {
  30. public:
  31. //==============================================================================
  32. /** Creates a TabbedComponent, specifying where the tabs should be placed.
  33. Once created, add some tabs with the addTab() method.
  34. */
  35. explicit TabbedComponent (TabbedButtonBar::Orientation orientation);
  36. /** Destructor. */
  37. ~TabbedComponent();
  38. //==============================================================================
  39. /** Changes the placement of the tabs.
  40. This will rearrange the layout to place the tabs along the appropriate
  41. side of this component, and will shift the content component accordingly.
  42. @see TabbedButtonBar::setOrientation
  43. */
  44. void setOrientation (TabbedButtonBar::Orientation orientation);
  45. /** Returns the current tab placement.
  46. @see setOrientation, TabbedButtonBar::getOrientation
  47. */
  48. TabbedButtonBar::Orientation getOrientation() const noexcept;
  49. /** Specifies how many pixels wide or high the tab-bar should be.
  50. If the tabs are placed along the top or bottom, this specified the height
  51. of the bar; if they're along the left or right edges, it'll be the width
  52. of the bar.
  53. */
  54. void setTabBarDepth (int newDepth);
  55. /** Returns the current thickness of the tab bar.
  56. @see setTabBarDepth
  57. */
  58. int getTabBarDepth() const noexcept { return tabDepth; }
  59. /** Specifies the thickness of an outline that should be drawn around the content component.
  60. If this thickness is > 0, a line will be drawn around the three sides of the content
  61. component which don't touch the tab-bar, and the content component will be inset by this amount.
  62. To set the colour of the line, use setColour (outlineColourId, ...).
  63. */
  64. void setOutline (int newThickness);
  65. /** Specifies a gap to leave around the edge of the content component.
  66. Each edge of the content component will be indented by the given number of pixels.
  67. */
  68. void setIndent (int indentThickness);
  69. //==============================================================================
  70. /** Removes all the tabs from the bar.
  71. @see TabbedButtonBar::clearTabs
  72. */
  73. void clearTabs();
  74. /** Adds a tab to the tab-bar.
  75. The component passed in will be shown for the tab. If deleteComponentWhenNotNeeded
  76. is true, then the TabbedComponent will take ownership of the component and will delete
  77. it when the tab is removed or when this object is deleted.
  78. @see TabbedButtonBar::addTab
  79. */
  80. void addTab (const String& tabName,
  81. Colour tabBackgroundColour,
  82. Component* contentComponent,
  83. bool deleteComponentWhenNotNeeded,
  84. int insertIndex = -1);
  85. /** Changes the name of one of the tabs. */
  86. void setTabName (int tabIndex, const String& newName);
  87. /** Gets rid of one of the tabs. */
  88. void removeTab (int tabIndex);
  89. /** Moves a tab to a new index in the list.
  90. Pass -1 as the index to move it to the end of the list.
  91. */
  92. void moveTab (int currentIndex, int newIndex, bool animate = false);
  93. /** Returns the number of tabs in the bar. */
  94. int getNumTabs() const;
  95. /** Returns a list of all the tab names in the bar. */
  96. StringArray getTabNames() const;
  97. /** Returns the content component that was added for the given index.
  98. Be careful not to reposition or delete the components that are returned, as
  99. this will interfere with the TabbedComponent's behaviour.
  100. */
  101. Component* getTabContentComponent (int tabIndex) const noexcept;
  102. /** Returns the colour of one of the tabs. */
  103. Colour getTabBackgroundColour (int tabIndex) const noexcept;
  104. /** Changes the background colour of one of the tabs. */
  105. void setTabBackgroundColour (int tabIndex, Colour newColour);
  106. //==============================================================================
  107. /** Changes the currently-selected tab.
  108. To deselect all the tabs, pass -1 as the index.
  109. @see TabbedButtonBar::setCurrentTabIndex
  110. */
  111. void setCurrentTabIndex (int newTabIndex, bool sendChangeMessage = true);
  112. /** Returns the index of the currently selected tab.
  113. @see addTab, TabbedButtonBar::getCurrentTabIndex()
  114. */
  115. int getCurrentTabIndex() const;
  116. /** Returns the name of the currently selected tab.
  117. @see addTab, TabbedButtonBar::getCurrentTabName()
  118. */
  119. String getCurrentTabName() const;
  120. /** Returns the current component that's filling the panel.
  121. This will return nullptr if there isn't one.
  122. */
  123. Component* getCurrentContentComponent() const noexcept { return panelComponent; }
  124. //==============================================================================
  125. /** Callback method to indicate the selected tab has been changed.
  126. @see setCurrentTabIndex
  127. */
  128. virtual void currentTabChanged (int newCurrentTabIndex, const String& newCurrentTabName);
  129. /** Callback method to indicate that the user has right-clicked on a tab. */
  130. virtual void popupMenuClickOnTab (int tabIndex, const String& tabName);
  131. /** Returns the tab button bar component that is being used. */
  132. TabbedButtonBar& getTabbedButtonBar() const noexcept { return *tabs; }
  133. //==============================================================================
  134. /** A set of colour IDs to use to change the colour of various aspects of the component.
  135. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  136. methods.
  137. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  138. */
  139. enum ColourIds
  140. {
  141. backgroundColourId = 0x1005800, /**< The colour to fill the background behind the tabs. */
  142. outlineColourId = 0x1005801, /**< The colour to use to draw an outline around the content.
  143. (See setOutline) */
  144. };
  145. //==============================================================================
  146. /** @internal */
  147. void paint (Graphics&) override;
  148. /** @internal */
  149. void resized() override;
  150. /** @internal */
  151. void lookAndFeelChanged() override;
  152. protected:
  153. //==============================================================================
  154. /** This creates one of the tab buttons.
  155. If you need to use custom tab components, you can override this method and
  156. return your own class instead of the default.
  157. */
  158. virtual TabBarButton* createTabButton (const String& tabName, int tabIndex);
  159. /** @internal */
  160. ScopedPointer<TabbedButtonBar> tabs;
  161. private:
  162. //==============================================================================
  163. Array <WeakReference<Component> > contentComponents;
  164. WeakReference<Component> panelComponent;
  165. int tabDepth, outlineThickness, edgeIndent;
  166. class ButtonBar;
  167. friend class ButtonBar;
  168. void changeCallback (int newCurrentTabIndex, const String& newTabName);
  169. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TabbedComponent)
  170. };