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_ChoicePropertyComponent.h 4.8KB

9 years ago
10 years ago
10 years ago
10 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI 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_CHOICEPROPERTYCOMPONENT_H_INCLUDED
  18. #define JUCE_CHOICEPROPERTYCOMPONENT_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. A PropertyComponent that shows its value as a combo box.
  22. This type of property component contains a list of options and has a
  23. combo box to choose one.
  24. Your subclass's constructor must add some strings to the choices StringArray
  25. and these are shown in the list.
  26. The getIndex() method will be called to find out which option is the currently
  27. selected one. If you call refresh() it will call getIndex() to check whether
  28. the value has changed, and will update the combo box if needed.
  29. If the user selects a different item from the list, setIndex() will be
  30. called to let your class process this.
  31. @see PropertyComponent, PropertyPanel
  32. */
  33. class JUCE_API ChoicePropertyComponent : public PropertyComponent,
  34. private ComboBoxListener // (can't use ComboBox::Listener due to idiotic VC2005 bug)
  35. {
  36. protected:
  37. /** Creates the component.
  38. Your subclass's constructor must add a list of options to the choices member variable.
  39. */
  40. ChoicePropertyComponent (const String& propertyName);
  41. public:
  42. /** Creates the component.
  43. Note that if you call this constructor then you must use the Value to interact with the
  44. index, and you can't override the class with your own setIndex or getIndex methods.
  45. If you want to use those methods, call the other constructor instead.
  46. @param valueToControl the value that the combo box will read and control
  47. @param propertyName the name of the property
  48. @param choices the list of possible values that the drop-down list will contain
  49. @param correspondingValues a list of values corresponding to each item in the 'choices' StringArray.
  50. These are the values that will be read and written to the
  51. valueToControl value. This array must contain the same number of items
  52. as the choices array
  53. */
  54. ChoicePropertyComponent (const Value& valueToControl,
  55. const String& propertyName,
  56. const StringArray& choices,
  57. const Array<var>& correspondingValues);
  58. /** Destructor. */
  59. ~ChoicePropertyComponent();
  60. //==============================================================================
  61. /** Called when the user selects an item from the combo box.
  62. Your subclass must use this callback to update the value that this component
  63. represents. The index is the index of the chosen item in the choices
  64. StringArray.
  65. */
  66. virtual void setIndex (int newIndex);
  67. /** Returns the index of the item that should currently be shown.
  68. This is the index of the item in the choices StringArray that will be shown.
  69. */
  70. virtual int getIndex() const;
  71. /** Returns the list of options. */
  72. const StringArray& getChoices() const;
  73. //==============================================================================
  74. /** @internal */
  75. void refresh();
  76. protected:
  77. /** The list of options that will be shown in the combo box.
  78. Your subclass must populate this array in its constructor. If any empty
  79. strings are added, these will be replaced with horizontal separators (see
  80. ComboBox::addSeparator() for more info).
  81. */
  82. StringArray choices;
  83. private:
  84. ComboBox comboBox;
  85. bool isCustomClass;
  86. class RemapperValueSource;
  87. void createComboBox();
  88. void comboBoxChanged (ComboBox*);
  89. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ChoicePropertyComponent)
  90. };
  91. #endif // JUCE_CHOICEPROPERTYCOMPONENT_H_INCLUDED