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_ToolbarItemComponent.h 8.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software 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_TOOLBARITEMCOMPONENT_H_INCLUDED
  18. #define JUCE_TOOLBARITEMCOMPONENT_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. A component that can be used as one of the items in a Toolbar.
  22. Each of the items on a toolbar must be a component derived from ToolbarItemComponent,
  23. and these objects are always created by a ToolbarItemFactory - see the ToolbarItemFactory
  24. class for further info about creating them.
  25. The ToolbarItemComponent class is actually a button, but can be used to hold non-button
  26. components too. To do this, set the value of isBeingUsedAsAButton to false when
  27. calling the constructor, and override contentAreaChanged(), in which you can position
  28. any sub-components you need to add.
  29. To add basic buttons without writing a special subclass, have a look at the
  30. ToolbarButton class.
  31. @see ToolbarButton, Toolbar, ToolbarItemFactory
  32. */
  33. class JUCE_API ToolbarItemComponent : public Button
  34. {
  35. public:
  36. //==============================================================================
  37. /** Constructor.
  38. @param itemId the ID of the type of toolbar item which this represents
  39. @param labelText the text to display if the toolbar's style is set to
  40. Toolbar::iconsWithText or Toolbar::textOnly
  41. @param isBeingUsedAsAButton set this to false if you don't want the button
  42. to draw itself with button over/down states when the mouse
  43. moves over it or clicks
  44. */
  45. ToolbarItemComponent (int itemId,
  46. const String& labelText,
  47. bool isBeingUsedAsAButton);
  48. /** Destructor. */
  49. ~ToolbarItemComponent();
  50. //==============================================================================
  51. /** Returns the item type ID that this component represents.
  52. This value is in the constructor.
  53. */
  54. int getItemId() const noexcept { return itemId; }
  55. /** Returns the toolbar that contains this component, or nullptr if it's not currently
  56. inside one.
  57. */
  58. Toolbar* getToolbar() const;
  59. /** Returns true if this component is currently inside a toolbar which is vertical.
  60. @see Toolbar::isVertical
  61. */
  62. bool isToolbarVertical() const;
  63. /** Returns the current style setting of this item.
  64. Styles are listed in the Toolbar::ToolbarItemStyle enum.
  65. @see setStyle, Toolbar::getStyle
  66. */
  67. Toolbar::ToolbarItemStyle getStyle() const noexcept { return toolbarStyle; }
  68. /** Changes the current style setting of this item.
  69. Styles are listed in the Toolbar::ToolbarItemStyle enum, and are automatically updated
  70. by the toolbar that holds this item.
  71. @see setStyle, Toolbar::setStyle
  72. */
  73. virtual void setStyle (const Toolbar::ToolbarItemStyle& newStyle);
  74. /** Returns the area of the component that should be used to display the button image or
  75. other contents of the item.
  76. This content area may change when the item's style changes, and may leave a space around the
  77. edge of the component where the text label can be shown.
  78. @see contentAreaChanged
  79. */
  80. const Rectangle<int>& getContentArea() const noexcept { return contentArea; }
  81. //==============================================================================
  82. /** This method must return the size criteria for this item, based on a given toolbar
  83. size and orientation.
  84. The preferredSize, minSize and maxSize values must all be set by your implementation
  85. method. If the toolbar is horizontal, these will be the width of the item; for a vertical
  86. toolbar, they refer to the item's height.
  87. The preferredSize is the size that the component would like to be, and this must be
  88. between the min and max sizes. For a fixed-size item, simply set all three variables to
  89. the same value.
  90. The toolbarThickness parameter tells you the depth of the toolbar - the same as calling
  91. Toolbar::getThickness().
  92. The isToolbarVertical parameter tells you whether the bar is oriented horizontally or
  93. vertically.
  94. */
  95. virtual bool getToolbarItemSizes (int toolbarThickness,
  96. bool isToolbarVertical,
  97. int& preferredSize,
  98. int& minSize,
  99. int& maxSize) = 0;
  100. /** Your subclass should use this method to draw its content area.
  101. The graphics object that is passed-in will have been clipped and had its origin
  102. moved to fit the content area as specified get getContentArea(). The width and height
  103. parameters are the width and height of the content area.
  104. If the component you're writing isn't a button, you can just do nothing in this method.
  105. */
  106. virtual void paintButtonArea (Graphics& g,
  107. int width, int height,
  108. bool isMouseOver, bool isMouseDown) = 0;
  109. /** Callback to indicate that the content area of this item has changed.
  110. This might be because the component was resized, or because the style changed and
  111. the space needed for the text label is different.
  112. See getContentArea() for a description of what the area is.
  113. */
  114. virtual void contentAreaChanged (const Rectangle<int>& newBounds) = 0;
  115. //==============================================================================
  116. /** Editing modes.
  117. These are used by setEditingMode(), but will be rarely needed in user code.
  118. */
  119. enum ToolbarEditingMode
  120. {
  121. normalMode = 0, /**< Means that the component is active, inside a toolbar. */
  122. editableOnToolbar, /**< Means that the component is on a toolbar, but the toolbar is in
  123. customisation mode, and the items can be dragged around. */
  124. editableOnPalette /**< Means that the component is on an new-item palette, so it can be
  125. dragged onto a toolbar to add it to that bar.*/
  126. };
  127. /** Changes the editing mode of this component.
  128. This is used by the ToolbarItemPalette and related classes for making the items draggable,
  129. and is unlikely to be of much use in end-user-code.
  130. */
  131. void setEditingMode (const ToolbarEditingMode newMode);
  132. /** Returns the current editing mode of this component.
  133. This is used by the ToolbarItemPalette and related classes for making the items draggable,
  134. and is unlikely to be of much use in end-user-code.
  135. */
  136. ToolbarEditingMode getEditingMode() const noexcept { return mode; }
  137. //==============================================================================
  138. /** @internal */
  139. void paintButton (Graphics&, bool isMouseOver, bool isMouseDown) override;
  140. /** @internal */
  141. void resized() override;
  142. private:
  143. friend class Toolbar;
  144. class ItemDragAndDropOverlayComponent;
  145. friend class ItemDragAndDropOverlayComponent;
  146. const int itemId;
  147. ToolbarEditingMode mode;
  148. Toolbar::ToolbarItemStyle toolbarStyle;
  149. ScopedPointer <Component> overlayComp;
  150. int dragOffsetX, dragOffsetY;
  151. bool isActive, isBeingDragged, isBeingUsedAsAButton;
  152. Rectangle<int> contentArea;
  153. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ToolbarItemComponent)
  154. };
  155. #endif // JUCE_TOOLBARITEMCOMPONENT_H_INCLUDED