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.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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_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
  39. member variable.
  40. */
  41. ChoicePropertyComponent (const String& propertyName);
  42. public:
  43. /** Creates the component.
  44. @param valueToControl the value that the combo box will read and control
  45. @param propertyName the name of the property
  46. @param choices the list of possible values that the drop-down list will contain
  47. @param correspondingValues a list of values corresponding to each item in the 'choices' StringArray.
  48. These are the values that will be read and written to the
  49. valueToControl value. This array must contain the same number of items
  50. as the choices array
  51. */
  52. ChoicePropertyComponent (const Value& valueToControl,
  53. const String& propertyName,
  54. const StringArray& choices,
  55. const Array <var>& correspondingValues);
  56. /** Destructor. */
  57. ~ChoicePropertyComponent();
  58. //==============================================================================
  59. /** Called when the user selects an item from the combo box.
  60. Your subclass must use this callback to update the value that this component
  61. represents. The index is the index of the chosen item in the choices
  62. StringArray.
  63. */
  64. virtual void setIndex (int newIndex);
  65. /** Returns the index of the item that should currently be shown.
  66. This is the index of the item in the choices StringArray that will be shown.
  67. */
  68. virtual int getIndex() const;
  69. /** Returns the list of options. */
  70. const StringArray& getChoices() const;
  71. //==============================================================================
  72. /** @internal */
  73. void refresh();
  74. protected:
  75. /** The list of options that will be shown in the combo box.
  76. Your subclass must populate this array in its constructor. If any empty
  77. strings are added, these will be replaced with horizontal separators (see
  78. ComboBox::addSeparator() for more info).
  79. */
  80. StringArray choices;
  81. private:
  82. ComboBox comboBox;
  83. bool isCustomClass;
  84. class RemapperValueSource;
  85. void createComboBox();
  86. void comboBoxChanged (ComboBox*);
  87. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ChoicePropertyComponent)
  88. };
  89. #endif // JUCE_CHOICEPROPERTYCOMPONENT_H_INCLUDED