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.

308 lines
11KB

  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_TABBEDBUTTONBAR_JUCEHEADER__
  19. #define __JUCE_TABBEDBUTTONBAR_JUCEHEADER__
  20. #include "../buttons/juce_Button.h"
  21. class TabbedButtonBar;
  22. //==============================================================================
  23. /** In a TabbedButtonBar, this component is used for each of the buttons.
  24. If you want to create a TabbedButtonBar with custom tab components, derive
  25. your component from this class, and override the TabbedButtonBar::createTabButton()
  26. method to create it instead of the default one.
  27. @see TabbedButtonBar
  28. */
  29. class JUCE_API TabBarButton : public Button
  30. {
  31. public:
  32. //==============================================================================
  33. /** Creates the tab button. */
  34. TabBarButton (const String& name, TabbedButtonBar& ownerBar);
  35. /** Destructor. */
  36. ~TabBarButton();
  37. //==============================================================================
  38. /** Chooses the best length for the tab, given the specified depth.
  39. If the tab is horizontal, this should return its width, and the depth
  40. specifies its height. If it's vertical, it should return the height, and
  41. the depth is actually its width.
  42. */
  43. virtual int getBestTabLength (int depth);
  44. //==============================================================================
  45. void paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown);
  46. void clicked (const ModifierKeys& mods);
  47. bool hitTest (int x, int y);
  48. protected:
  49. //==============================================================================
  50. friend class TabbedButtonBar;
  51. TabbedButtonBar& owner;
  52. int overlapPixels;
  53. DropShadowEffect shadow;
  54. /** Returns an area of the component that's safe to draw in.
  55. This deals with the orientation of the tabs, which affects which side is
  56. touching the tabbed box's content component.
  57. */
  58. Rectangle<int> getActiveArea();
  59. /** Returns this tab's index in its tab bar. */
  60. int getIndex() const;
  61. private:
  62. //==============================================================================
  63. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TabBarButton);
  64. };
  65. //==============================================================================
  66. /**
  67. A vertical or horizontal bar containing tabs that you can select.
  68. You can use one of these to generate things like a dialog box that has
  69. tabbed pages you can flip between. Attach a ChangeListener to the
  70. button bar to be told when the user changes the page.
  71. An easier method than doing this is to use a TabbedComponent, which
  72. contains its own TabbedButtonBar and which takes care of the layout
  73. and other housekeeping.
  74. @see TabbedComponent
  75. */
  76. class JUCE_API TabbedButtonBar : public Component,
  77. public ChangeBroadcaster
  78. {
  79. public:
  80. //==============================================================================
  81. /** The placement of the tab-bar
  82. @see setOrientation, getOrientation
  83. */
  84. enum Orientation
  85. {
  86. TabsAtTop,
  87. TabsAtBottom,
  88. TabsAtLeft,
  89. TabsAtRight
  90. };
  91. //==============================================================================
  92. /** Creates a TabbedButtonBar with a given placement.
  93. You can change the orientation later if you need to.
  94. */
  95. TabbedButtonBar (Orientation orientation);
  96. /** Destructor. */
  97. ~TabbedButtonBar();
  98. //==============================================================================
  99. /** Changes the bar's orientation.
  100. This won't change the bar's actual size - you'll need to do that yourself,
  101. but this determines which direction the tabs go in, and which side they're
  102. stuck to.
  103. */
  104. void setOrientation (Orientation orientation);
  105. /** Returns the current orientation.
  106. @see setOrientation
  107. */
  108. Orientation getOrientation() const noexcept { return orientation; }
  109. /** Changes the minimum scale factor to which the tabs can be compressed when trying to
  110. fit a lot of tabs on-screen.
  111. */
  112. void setMinimumTabScaleFactor (double newMinimumScale);
  113. //==============================================================================
  114. /** Deletes all the tabs from the bar.
  115. @see addTab
  116. */
  117. void clearTabs();
  118. /** Adds a tab to the bar.
  119. Tabs are added in left-to-right reading order.
  120. If this is the first tab added, it'll also be automatically selected.
  121. */
  122. void addTab (const String& tabName,
  123. const Colour& tabBackgroundColour,
  124. int insertIndex = -1);
  125. /** Changes the name of one of the tabs. */
  126. void setTabName (int tabIndex,
  127. const String& newName);
  128. /** Gets rid of one of the tabs. */
  129. void removeTab (int tabIndex);
  130. /** Moves a tab to a new index in the list.
  131. Pass -1 as the index to move it to the end of the list.
  132. */
  133. void moveTab (int currentIndex, int newIndex);
  134. /** Returns the number of tabs in the bar. */
  135. int getNumTabs() const;
  136. /** Returns a list of all the tab names in the bar. */
  137. StringArray getTabNames() const;
  138. /** Changes the currently selected tab.
  139. This will send a change message and cause a synchronous callback to
  140. the currentTabChanged() method. (But if the given tab is already selected,
  141. nothing will be done).
  142. To deselect all the tabs, use an index of -1.
  143. */
  144. void setCurrentTabIndex (int newTabIndex, bool sendChangeMessage = true);
  145. /** Returns the name of the currently selected tab.
  146. This could be an empty string if none are selected.
  147. */
  148. String getCurrentTabName() const;
  149. /** Returns the index of the currently selected tab.
  150. This could return -1 if none are selected.
  151. */
  152. int getCurrentTabIndex() const noexcept { return currentTabIndex; }
  153. /** Returns the button for a specific tab.
  154. The button that is returned may be deleted later by this component, so don't hang
  155. on to the pointer that is returned. A null pointer may be returned if the index is
  156. out of range.
  157. */
  158. TabBarButton* getTabButton (int index) const;
  159. /** Returns the index of a TabBarButton if it belongs to this bar. */
  160. int indexOfTabButton (const TabBarButton* button) const;
  161. //==============================================================================
  162. /** Callback method to indicate the selected tab has been changed.
  163. @see setCurrentTabIndex
  164. */
  165. virtual void currentTabChanged (int newCurrentTabIndex,
  166. const String& newCurrentTabName);
  167. /** Callback method to indicate that the user has right-clicked on a tab.
  168. (Or ctrl-clicked on the Mac)
  169. */
  170. virtual void popupMenuClickOnTab (int tabIndex, const String& tabName);
  171. /** Returns the colour of a tab.
  172. This is the colour that was specified in addTab().
  173. */
  174. Colour getTabBackgroundColour (int tabIndex);
  175. /** Changes the background colour of a tab.
  176. @see addTab, getTabBackgroundColour
  177. */
  178. void setTabBackgroundColour (int tabIndex, const Colour& newColour);
  179. //==============================================================================
  180. /** A set of colour IDs to use to change the colour of various aspects of the component.
  181. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  182. methods.
  183. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  184. */
  185. enum ColourIds
  186. {
  187. tabOutlineColourId = 0x1005812, /**< The colour to use to draw an outline around the tabs. */
  188. tabTextColourId = 0x1005813, /**< The colour to use to draw the tab names. If this isn't specified,
  189. the look and feel will choose an appropriate colour. */
  190. frontOutlineColourId = 0x1005814, /**< The colour to use to draw an outline around the currently-selected tab. */
  191. frontTextColourId = 0x1005815, /**< The colour to use to draw the currently-selected tab name. If
  192. this isn't specified, the look and feel will choose an appropriate
  193. colour. */
  194. };
  195. //==============================================================================
  196. /** @internal */
  197. void resized();
  198. /** @internal */
  199. void lookAndFeelChanged();
  200. protected:
  201. //==============================================================================
  202. /** This creates one of the tabs.
  203. If you need to use custom tab components, you can override this method and
  204. return your own class instead of the default.
  205. */
  206. virtual TabBarButton* createTabButton (const String& tabName, int tabIndex);
  207. private:
  208. Orientation orientation;
  209. struct TabInfo
  210. {
  211. ScopedPointer<TabBarButton> component;
  212. String name;
  213. Colour colour;
  214. };
  215. OwnedArray <TabInfo> tabs;
  216. double minimumScale;
  217. int currentTabIndex;
  218. class BehindFrontTabComp;
  219. friend class BehindFrontTabComp;
  220. friend class ScopedPointer<BehindFrontTabComp>;
  221. ScopedPointer<BehindFrontTabComp> behindFrontTab;
  222. ScopedPointer<Button> extraTabsButton;
  223. void showExtraItemsMenu();
  224. static void extraItemsMenuCallback (int, TabbedButtonBar*);
  225. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TabbedButtonBar);
  226. };
  227. #endif // __JUCE_TABBEDBUTTONBAR_JUCEHEADER__