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.

239 lines
8.6KB

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