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.

131 lines
4.9KB

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