VST3: fetch midi mappings all at once, use it for note/sound-off
[carla.git] / source / modules / juce_gui_basics / properties / juce_TextPropertyComponent.h
blob16d88ef327608819eedfb9d70aa83b0f4edf4178
1 /*
2 ==============================================================================
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
23 ==============================================================================
26 namespace juce
29 //==============================================================================
30 /**
31 A PropertyComponent that shows its value as editable text.
33 @see PropertyComponent
35 @tags{GUI}
37 class JUCE_API TextPropertyComponent : public PropertyComponent
39 protected:
40 //==============================================================================
41 /** Creates a text property component.
43 @param propertyName The name of the property
44 @param maxNumChars If not zero, then this specifies the maximum allowable length of
45 the string. If zero, then the string will have no length limit.
46 @param isMultiLine Sets whether the text editor allows carriage returns.
47 @param isEditable Sets whether the text editor is editable. The default is true.
49 @see TextEditor, setEditable
51 TextPropertyComponent (const String& propertyName,
52 int maxNumChars,
53 bool isMultiLine,
54 bool isEditable = true);
56 public:
57 /** Creates a text property component.
59 @param valueToControl The Value that is controlled by the TextPropertyComponent
60 @param propertyName The name of the property
61 @param maxNumChars If not zero, then this specifies the maximum allowable length of
62 the string. If zero, then the string will have no length limit.
63 @param isMultiLine Sets whether the text editor allows carriage returns.
64 @param isEditable Sets whether the text editor is editable. The default is true.
66 @see TextEditor, setEditable
68 TextPropertyComponent (const Value& valueToControl,
69 const String& propertyName,
70 int maxNumChars,
71 bool isMultiLine,
72 bool isEditable = true);
74 /** Creates a text property component with a default value.
76 @param valueToControl The ValueTreePropertyWithDefault that is controlled by the TextPropertyComponent.
77 @param propertyName The name of the property
78 @param maxNumChars If not zero, then this specifies the maximum allowable length of
79 the string. If zero, then the string will have no length limit.
80 @param isMultiLine Sets whether the text editor allows carriage returns.
81 @param isEditable Sets whether the text editor is editable. The default is true.
83 @see TextEditor, setEditable
85 TextPropertyComponent (const ValueTreePropertyWithDefault& valueToControl,
86 const String& propertyName,
87 int maxNumChars,
88 bool isMultiLine,
89 bool isEditable = true);
91 ~TextPropertyComponent() override;
93 //==============================================================================
94 /** Called when the user edits the text.
96 Your subclass must use this callback to change the value of whatever item
97 this property component represents.
99 virtual void setText (const String& newText);
101 /** Returns the text that should be shown in the text editor. */
102 virtual String getText() const;
104 /** Returns the text that should be shown in the text editor as a Value object. */
105 Value& getValue() const;
107 //==============================================================================
108 /** Returns true if the text editor allows carriage returns. */
109 bool isTextEditorMultiLine() const noexcept { return isMultiLine; }
111 //==============================================================================
112 /** A set of colour IDs to use to change the colour of various aspects of the component.
114 These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
115 methods.
117 @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
119 enum ColourIds
121 backgroundColourId = 0x100e401, /**< The colour to fill the background of the text area. */
122 textColourId = 0x100e402, /**< The colour to use for the editable text. */
123 outlineColourId = 0x100e403, /**< The colour to use to draw an outline around the text area. */
126 void colourChanged() override;
128 //==============================================================================
129 /** Used to receive callbacks for text changes */
130 class JUCE_API Listener
132 public:
133 /** Destructor. */
134 virtual ~Listener() = default;
136 /** Called when text has finished being entered (i.e. not per keypress) has changed. */
137 virtual void textPropertyComponentChanged (TextPropertyComponent*) = 0;
140 /** Registers a listener to receive events when this button's state changes.
141 If the listener is already registered, this will not register it again.
142 @see removeListener
144 void addListener (Listener* newListener);
146 /** Removes a previously-registered button listener
147 @see addListener
149 void removeListener (Listener* listener);
151 //==============================================================================
152 /** Sets whether the text property component can have files dropped onto it by an external application.
154 The default setting for this is true but you may want to disable this behaviour if you derive
155 from this class and want your subclass to respond to the file drag.
157 void setInterestedInFileDrag (bool isInterested);
159 /** Sets whether the text editor is editable. The default setting for this is true. */
160 void setEditable (bool isEditable);
162 //==============================================================================
163 /** @internal */
164 void refresh() override;
165 /** @internal */
166 virtual void textWasEdited();
168 private:
169 //==============================================================================
170 void callListeners();
171 void createEditor (int maxNumChars, bool isEditable);
173 //==============================================================================
174 class LabelComp;
176 const bool isMultiLine;
178 ValueTreePropertyWithDefault value;
179 std::unique_ptr<LabelComp> textEditor;
180 ListenerList<Listener> listenerList;
182 //==============================================================================
183 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TextPropertyComponent)
187 } // namespace juce