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.

243 lines
8.9KB

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