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.

125 lines
5.2KB

  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_PROPERTYCOMPONENT_JUCEHEADER__
  19. #define __JUCE_PROPERTYCOMPONENT_JUCEHEADER__
  20. class EditableProperty;
  21. #include "../components/juce_Component.h"
  22. #include "../mouse/juce_TooltipClient.h"
  23. //==============================================================================
  24. /**
  25. A base class for a component that goes in a PropertyPanel and displays one of
  26. an item's properties.
  27. Subclasses of this are used to display a property in various forms, e.g. a
  28. ChoicePropertyComponent shows its value as a combo box; a SliderPropertyComponent
  29. shows its value as a slider; a TextPropertyComponent as a text box, etc.
  30. A subclass must implement the refresh() method which will be called to tell the
  31. component to update itself, and is also responsible for calling this it when the
  32. item that it refers to is changed.
  33. @see PropertyPanel, TextPropertyComponent, SliderPropertyComponent,
  34. ChoicePropertyComponent, ButtonPropertyComponent, BooleanPropertyComponent
  35. */
  36. class JUCE_API PropertyComponent : public Component,
  37. public SettableTooltipClient
  38. {
  39. public:
  40. //==============================================================================
  41. /** Creates a PropertyComponent.
  42. @param propertyName the name is stored as this component's name, and is
  43. used as the name displayed next to this component in
  44. a property panel
  45. @param preferredHeight the height that the component should be given - some
  46. items may need to be larger than a normal row height.
  47. This value can also be set if a subclass changes the
  48. preferredHeight member variable.
  49. */
  50. PropertyComponent (const String& propertyName,
  51. int preferredHeight = 25);
  52. /** Destructor. */
  53. ~PropertyComponent();
  54. //==============================================================================
  55. /** Returns this item's preferred height.
  56. This value is specified either in the constructor or by a subclass changing the
  57. preferredHeight member variable.
  58. */
  59. int getPreferredHeight() const noexcept { return preferredHeight; }
  60. void setPreferredHeight (int newHeight) noexcept { preferredHeight = newHeight; }
  61. //==============================================================================
  62. /** Updates the property component if the item it refers to has changed.
  63. A subclass must implement this method, and other objects may call it to
  64. force it to refresh itself.
  65. The subclass should be economical in the amount of work is done, so for
  66. example it should check whether it really needs to do a repaint rather than
  67. just doing one every time this method is called, as it may be called when
  68. the value being displayed hasn't actually changed.
  69. */
  70. virtual void refresh() = 0;
  71. /** The default paint method fills the background and draws a label for the
  72. item's name.
  73. @see LookAndFeel::drawPropertyComponentBackground(), LookAndFeel::drawPropertyComponentLabel()
  74. */
  75. void paint (Graphics& g);
  76. /** The default resize method positions any child component to the right of this
  77. one, based on the look and feel's default label size.
  78. */
  79. void resized();
  80. /** By default, this just repaints the component. */
  81. void enablementChanged();
  82. protected:
  83. /** Used by the PropertyPanel to determine how high this component needs to be.
  84. A subclass can update this value in its constructor but shouldn't alter it later
  85. as changes won't necessarily be picked up.
  86. */
  87. int preferredHeight;
  88. private:
  89. //==============================================================================
  90. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PropertyComponent);
  91. };
  92. #endif // __JUCE_PROPERTYCOMPONENT_JUCEHEADER__