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.

165 lines
6.0KB

  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_PROPERTYPANEL_JUCEHEADER__
  19. #define __JUCE_PROPERTYPANEL_JUCEHEADER__
  20. #include "juce_PropertyComponent.h"
  21. #include "../layout/juce_Viewport.h"
  22. //==============================================================================
  23. /**
  24. A panel that holds a list of PropertyComponent objects.
  25. This panel displays a list of PropertyComponents, and allows them to be organised
  26. into collapsible sections.
  27. To use, simply create one of these and add your properties to it with addProperties()
  28. or addSection().
  29. @see PropertyComponent
  30. */
  31. class JUCE_API PropertyPanel : public Component
  32. {
  33. public:
  34. //==============================================================================
  35. /** Creates an empty property panel. */
  36. PropertyPanel();
  37. /** Destructor. */
  38. ~PropertyPanel();
  39. //==============================================================================
  40. /** Deletes all property components from the panel.
  41. */
  42. void clear();
  43. /** Adds a set of properties to the panel.
  44. The components in the list will be owned by this object and will be automatically
  45. deleted later on when no longer needed.
  46. These properties are added without them being inside a named section. If you
  47. want them to be kept together in a collapsible section, use addSection() instead.
  48. */
  49. void addProperties (const Array <PropertyComponent*>& newPropertyComponents);
  50. /** Adds a set of properties to the panel.
  51. These properties are added at the bottom of the list, under a section heading with
  52. a plus/minus button that allows it to be opened and closed.
  53. The components in the list will be owned by this object and will be automatically
  54. deleted later on when no longer needed.
  55. To add properies without them being in a section, use addProperties().
  56. */
  57. void addSection (const String& sectionTitle,
  58. const Array <PropertyComponent*>& newPropertyComponents,
  59. bool shouldSectionInitiallyBeOpen = true);
  60. /** Calls the refresh() method of all PropertyComponents in the panel */
  61. void refreshAll() const;
  62. //==============================================================================
  63. /** Returns a list of all the names of sections in the panel.
  64. These are the sections that have been added with addSection().
  65. */
  66. StringArray getSectionNames() const;
  67. /** Returns true if the section at this index is currently open.
  68. The index is from 0 up to the number of items returned by getSectionNames().
  69. */
  70. bool isSectionOpen (int sectionIndex) const;
  71. /** Opens or closes one of the sections.
  72. The index is from 0 up to the number of items returned by getSectionNames().
  73. */
  74. void setSectionOpen (int sectionIndex, bool shouldBeOpen);
  75. /** Enables or disables one of the sections.
  76. The index is from 0 up to the number of items returned by getSectionNames().
  77. */
  78. void setSectionEnabled (int sectionIndex, bool shouldBeEnabled);
  79. //==============================================================================
  80. /** Saves the current state of open/closed sections so it can be restored later.
  81. The caller is responsible for deleting the object that is returned.
  82. To restore this state, use restoreOpennessState().
  83. @see restoreOpennessState
  84. */
  85. XmlElement* getOpennessState() const;
  86. /** Restores a previously saved arrangement of open/closed sections.
  87. This will try to restore a snapshot of the panel's state that was created by
  88. the getOpennessState() method. If any of the sections named in the original
  89. XML aren't present, they will be ignored.
  90. @see getOpennessState
  91. */
  92. void restoreOpennessState (const XmlElement& newState);
  93. //==============================================================================
  94. /** Sets a message to be displayed when there are no properties in the panel.
  95. The default message is "nothing selected".
  96. */
  97. void setMessageWhenEmpty (const String& newMessage);
  98. /** Returns the message that is displayed when there are no properties.
  99. @see setMessageWhenEmpty
  100. */
  101. const String& getMessageWhenEmpty() const;
  102. //==============================================================================
  103. /** @internal */
  104. void paint (Graphics& g);
  105. /** @internal */
  106. void resized();
  107. private:
  108. Viewport viewport;
  109. class PropertyHolderComponent;
  110. PropertyHolderComponent* propertyHolderComponent;
  111. String messageWhenEmpty;
  112. void updatePropHolderLayout() const;
  113. void updatePropHolderLayout (int width) const;
  114. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PropertyPanel);
  115. };
  116. #endif // __JUCE_PROPERTYPANEL_JUCEHEADER__