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) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. namespace juce
  20. {
  21. //==============================================================================
  22. /**
  23. A PropertyComponent that shows its value as a combo box.
  24. This type of property component contains a list of options and has a
  25. combo box to choose one.
  26. Your subclass's constructor must add some strings to the choices StringArray
  27. and these are shown in the list.
  28. The getIndex() method will be called to find out which option is the currently
  29. selected one. If you call refresh() it will call getIndex() to check whether
  30. the value has changed, and will update the combo box if needed.
  31. If the user selects a different item from the list, setIndex() will be
  32. called to let your class process this.
  33. @see PropertyComponent, PropertyPanel
  34. */
  35. class JUCE_API ChoicePropertyComponent : public PropertyComponent,
  36. private ComboBox::Listener
  37. {
  38. protected:
  39. /** Creates the component.
  40. Your subclass's constructor must add a list of options to the choices member variable.
  41. */
  42. ChoicePropertyComponent (const String& propertyName);
  43. public:
  44. /** Creates the component.
  45. Note that if you call this constructor then you must use the Value to interact with the
  46. index, and you can't override the class with your own setIndex or getIndex methods.
  47. If you want to use those methods, call the other constructor instead.
  48. @param valueToControl the value that the combo box will read and control
  49. @param propertyName the name of the property
  50. @param choices the list of possible values that the drop-down list will contain
  51. @param correspondingValues a list of values corresponding to each item in the 'choices' StringArray.
  52. These are the values that will be read and written to the
  53. valueToControl value. This array must contain the same number of items
  54. as the choices array
  55. */
  56. ChoicePropertyComponent (const Value& valueToControl,
  57. const String& propertyName,
  58. const StringArray& choices,
  59. const Array<var>& correspondingValues);
  60. /** Destructor. */
  61. ~ChoicePropertyComponent();
  62. //==============================================================================
  63. /** Called when the user selects an item from the combo box.
  64. Your subclass must use this callback to update the value that this component
  65. represents. The index is the index of the chosen item in the choices
  66. StringArray.
  67. */
  68. virtual void setIndex (int newIndex);
  69. /** Returns the index of the item that should currently be shown.
  70. This is the index of the item in the choices StringArray that will be shown.
  71. */
  72. virtual int getIndex() const;
  73. /** Returns the list of options. */
  74. const StringArray& getChoices() const;
  75. //==============================================================================
  76. /** @internal */
  77. void refresh();
  78. protected:
  79. /** The list of options that will be shown in the combo box.
  80. Your subclass must populate this array in its constructor. If any empty
  81. strings are added, these will be replaced with horizontal separators (see
  82. ComboBox::addSeparator() for more info).
  83. */
  84. StringArray choices;
  85. private:
  86. ComboBox comboBox;
  87. bool isCustomClass;
  88. class RemapperValueSource;
  89. void createComboBox();
  90. void comboBoxChanged (ComboBox*);
  91. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ChoicePropertyComponent)
  92. };
  93. } // namespace juce