123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- /*
- ==============================================================================
- This file is part of the JUCE library.
- Copyright (c) 2013 - Raw Material Software Ltd.
- Permission is granted to use this software under the terms of either:
- a) the GPL v2 (or any later version)
- b) the Affero GPL v3
- Details of these licenses can be found at: www.gnu.org/licenses
- JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
- ------------------------------------------------------------------------------
- To release a closed-source product which uses JUCE, commercial licenses are
- available: visit www.juce.com for more information.
- ==============================================================================
- */
- class TextPropertyComponent::LabelComp : public Label,
- public FileDragAndDropTarget
- {
- public:
- LabelComp (TextPropertyComponent& tpc, const int charLimit, const bool multiline)
- : Label (String::empty, String::empty),
- owner (tpc),
- maxChars (charLimit),
- isMultiline (multiline)
- {
- setEditable (true, true, false);
- setColour (backgroundColourId, owner.findColour (TextPropertyComponent::backgroundColourId));
- setColour (outlineColourId, owner.findColour (TextPropertyComponent::outlineColourId));
- setColour (textColourId, owner.findColour (TextPropertyComponent::textColourId));
- }
- bool isInterestedInFileDrag (const StringArray&) override
- {
- return true;
- }
- void filesDropped (const StringArray& files, int, int) override
- {
- setText (getText() + files.joinIntoString (isMultiline ? "\n" : ", "), sendNotificationSync);
- showEditor();
- }
- TextEditor* createEditorComponent() override
- {
- TextEditor* const ed = Label::createEditorComponent();
- ed->setInputRestrictions (maxChars);
- if (isMultiline)
- {
- ed->setMultiLine (true, true);
- ed->setReturnKeyStartsNewLine (true);
- }
- return ed;
- }
- void textWasEdited() override
- {
- owner.textWasEdited();
- }
- private:
- TextPropertyComponent& owner;
- int maxChars;
- bool isMultiline;
- };
- //==============================================================================
- TextPropertyComponent::TextPropertyComponent (const String& name,
- const int maxNumChars,
- const bool isMultiLine)
- : PropertyComponent (name)
- {
- createEditor (maxNumChars, isMultiLine);
- }
- TextPropertyComponent::TextPropertyComponent (const Value& valueToControl,
- const String& name,
- const int maxNumChars,
- const bool isMultiLine)
- : PropertyComponent (name)
- {
- createEditor (maxNumChars, isMultiLine);
- textEditor->getTextValue().referTo (valueToControl);
- }
- TextPropertyComponent::~TextPropertyComponent()
- {
- }
- void TextPropertyComponent::setText (const String& newText)
- {
- textEditor->setText (newText, sendNotificationSync);
- }
- String TextPropertyComponent::getText() const
- {
- return textEditor->getText();
- }
- void TextPropertyComponent::createEditor (const int maxNumChars, const bool isMultiLine)
- {
- addAndMakeVisible (textEditor = new LabelComp (*this, maxNumChars, isMultiLine));
- if (isMultiLine)
- {
- textEditor->setJustificationType (Justification::topLeft);
- preferredHeight = 100;
- }
- }
- void TextPropertyComponent::refresh()
- {
- textEditor->setText (getText(), dontSendNotification);
- }
- void TextPropertyComponent::textWasEdited()
- {
- const String newText (textEditor->getText());
- if (getText() != newText)
- setText (newText);
- }
|