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_TabbedComponent.h 8.5KB

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