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.

126 lines
4.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-9 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 "../controls/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
  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. Your subclass's constructor must add a list of options to the choices
  48. member variable.
  49. */
  50. ChoicePropertyComponent (const Value& valueToControl,
  51. const String& propertyName,
  52. const StringArray& choices);
  53. /** Destructor. */
  54. ~ChoicePropertyComponent();
  55. //==============================================================================
  56. /** Called when the user selects an item from the combo box.
  57. Your subclass must use this callback to update the value that this component
  58. represents. The index is the index of the chosen item in the choices
  59. StringArray.
  60. */
  61. virtual void setIndex (const int newIndex);
  62. /** Returns the index of the item that should currently be shown.
  63. This is the index of the item in the choices StringArray that will be
  64. shown.
  65. */
  66. virtual int getIndex() const;
  67. /** Returns the list of options. */
  68. const StringArray& getChoices() const;
  69. //==============================================================================
  70. /** @internal */
  71. void refresh();
  72. /** @internal */
  73. void comboBoxChanged (ComboBox*);
  74. juce_UseDebuggingNewOperator
  75. protected:
  76. /** The list of options that will be shown in the combo box.
  77. Your subclass must populate this array in its constructor. If any empty
  78. strings are added, these will be replaced with horizontal separators (see
  79. ComboBox::addSeparator() for more info).
  80. */
  81. StringArray choices;
  82. private:
  83. ComboBox* comboBox;
  84. void createComboBox();
  85. ChoicePropertyComponent (const ChoicePropertyComponent&);
  86. const ChoicePropertyComponent& operator= (const ChoicePropertyComponent&);
  87. };
  88. #endif // __JUCE_CHOICEPROPERTYCOMPONENT_JUCEHEADER__