juce_TextPropertyComponent.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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_TEXTPROPERTYCOMPONENT_H_INCLUDED
  18. #define JUCE_TEXTPROPERTYCOMPONENT_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. A PropertyComponent that shows its value as editable text.
  22. @see PropertyComponent
  23. */
  24. class JUCE_API TextPropertyComponent : public PropertyComponent
  25. {
  26. protected:
  27. //==============================================================================
  28. /** Creates a text property component.
  29. The maxNumChars is used to set the length of string allowable, and isMultiLine
  30. sets whether the text editor allows carriage returns.
  31. @see TextEditor
  32. */
  33. TextPropertyComponent (const String& propertyName,
  34. int maxNumChars,
  35. bool isMultiLine);
  36. public:
  37. /** Creates a text property component.
  38. The maxNumChars is used to set the length of string allowable, and isMultiLine
  39. sets whether the text editor allows carriage returns.
  40. @see TextEditor
  41. */
  42. TextPropertyComponent (const Value& valueToControl,
  43. const String& propertyName,
  44. int maxNumChars,
  45. bool isMultiLine);
  46. /** Destructor. */
  47. ~TextPropertyComponent();
  48. //==============================================================================
  49. /** Called when the user edits the text.
  50. Your subclass must use this callback to change the value of whatever item
  51. this property component represents.
  52. */
  53. virtual void setText (const String& newText);
  54. /** Returns the text that should be shown in the text editor. */
  55. virtual String getText() const;
  56. //==============================================================================
  57. /** A set of colour IDs to use to change the colour of various aspects of the component.
  58. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  59. methods.
  60. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  61. */
  62. enum ColourIds
  63. {
  64. backgroundColourId = 0x100e401, /**< The colour to fill the background of the text area. */
  65. textColourId = 0x100e402, /**< The colour to use for the editable text. */
  66. outlineColourId = 0x100e403, /**< The colour to use to draw an outline around the text area. */
  67. };
  68. //==============================================================================
  69. /** @internal */
  70. void refresh();
  71. private:
  72. ScopedPointer<Label> textEditor;
  73. class LabelComp;
  74. friend class LabelComp;
  75. void textWasEdited();
  76. void createEditor (int maxNumChars, bool isMultiLine);
  77. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TextPropertyComponent)
  78. };
  79. #endif // JUCE_TEXTPROPERTYCOMPONENT_H_INCLUDED