78 void setMultiLine (
bool shouldBeMultiLine,
79 bool shouldWordWrap =
true);
82 bool isMultiLine()
const;
92 void setReturnKeyStartsNewLine (
bool shouldStartNewLine);
105 void setTabKeyUsedAsCharacter (
bool shouldTabKeyBeUsed);
118 void setEscapeAndReturnKeysConsumed (
bool shouldBeConsumed)
noexcept;
130 void setReadOnly (
bool shouldBeReadOnly);
133 bool isReadOnly() const noexcept;
140 void setCaretVisible (
bool shouldBeVisible);
145 bool isCaretVisible() const noexcept {
return caretVisible && ! isReadOnly(); }
156 void setScrollbarsShown (
bool shouldBeEnabled);
172 void setPasswordCharacter (
juce_wchar passwordCharacter);
187 void setPopupMenuEnabled (
bool menuEnabled);
209 backgroundColourId = 0x1000200,
212 textColourId = 0x1000201,
217 highlightColourId = 0x1000202,
221 highlightedTextColourId = 0x1000203,
223 outlineColourId = 0x1000205,
226 focusedOutlineColourId = 0x1000206,
229 shadowColourId = 0x1000207,
242 void setFont (
const Font& newFont);
251 void applyFontToAllText (
const Font& newFont,
bool changeCurrentFont =
true);
264 void applyColourToAllText (
const Colour& newColour,
bool changeCurrentTextColour =
true);
286 void setSelectAllWhenFocused (
bool shouldSelectAll);
294 void setTextToShowWhenEmpty (
const String& text,
Colour colourToUse);
306 void setScrollBarThickness (
int newThicknessPixels);
336 void addListener (Listener* newListener);
341 void removeListener (Listener* listenerToRemove);
366 bool isEmpty()
const;
380 void setText (
const String& newText,
381 bool sendTextChangeMessage =
true);
389 Value& getTextValue();
401 void insertTextAtCaret (
const String& textToInsert)
override;
426 int getCaretPosition()
const override;
431 void setCaretPosition (
int newIndex);
444 void scrollEditorToPositionCaret (
int desiredCaretX,
int desiredCaretY);
450 Rectangle<int> getCaretRectangleForCharIndex (
int index)
const override;
453 void setHighlightedRegion (
const Range<int>& newSelection)
override;
462 String getHighlightedText()
const;
467 int getTextIndexAt (
int x,
int y)
const;
477 int getCharIndexForPoint (
Point<int> point)
const override;
484 int getTotalNumChars()
const override;
491 int getTextWidth()
const;
498 int getTextHeight()
const;
503 void setIndents (
int newLeftIndent,
int newTopIndent);
530 void setScrollToShowCursor (
bool shouldScrollToShowCaret);
556 void moveCaretToEnd();
557 bool moveCaretLeft (
bool moveInWholeWordSteps,
bool selecting);
558 bool moveCaretRight (
bool moveInWholeWordSteps,
bool selecting);
559 bool moveCaretUp (
bool selecting);
560 bool moveCaretDown (
bool selecting);
561 bool pageUp (
bool selecting);
562 bool pageDown (
bool selecting);
565 bool moveCaretToTop (
bool selecting);
566 bool moveCaretToStartOfLine (
bool selecting);
567 bool moveCaretToEnd (
bool selecting);
568 bool moveCaretToEndOfLine (
bool selecting);
569 bool deleteBackwards (
bool moveInWholeWordSteps);
570 bool deleteForwards (
bool moveInWholeWordSteps);
571 bool copyToClipboard();
572 bool cutToClipboard();
573 bool pasteFromClipboard();
599 virtual void addPopupMenuItems (
PopupMenu& menuToAddTo,
613 virtual void performPopupMenuAction (
int menuItemID);
660 void setInputFilter (
InputFilter* newFilter,
bool takeOwnership);
674 void setInputRestrictions (
int maxTextLength,
688 void setClicksOutsideDismissVirtualKeyboard (
bool);
703 virtual void fillTextEditorBackground (
Graphics&,
int width,
int height,
TextEditor&) = 0;
704 virtual void drawTextEditorOutline (
Graphics&,
int width,
int height,
TextEditor&) = 0;
713 void paintOverChildren (
Graphics&)
override;
721 void mouseDoubleClick (
const MouseEvent&)
override;
725 bool keyPressed (
const KeyPress&)
override;
727 bool keyStateChanged (
bool)
override;
733 void resized()
override;
735 void enablementChanged()
override;
737 void lookAndFeelChanged()
override;
739 void parentHierarchyChanged()
override;
741 bool isTextInputActive()
const override;
752 void scrollToMakeSureCursorIsVisible();
758 void newTransaction();
761 virtual void returnPressed();
764 virtual void escapePressed();
779 explicit GlobalMouseListener (
Component& e) : editor (e) { Desktop::getInstance().addGlobalMouseListener (
this); }
780 ~GlobalMouseListener()
override { Desktop::getInstance().removeGlobalMouseListener (
this); }
782 bool lastMouseDownInEditor()
const {
return mouseDownInEditor; }
785 void mouseDown (
const MouseEvent& event)
override { mouseDownInEditor =
event.originalComponent == &editor; }
788 bool mouseDownInEditor =
false;
792 TextHolderComponent* textHolder;
793 BorderSize<int> borderSize { 1, 1, 1, 3 };
794 Justification justification { Justification::topLeft };
795 const GlobalMouseListener globalMouseListener { *
this };
797 bool readOnly =
false;
798 bool caretVisible =
true;
799 bool multiline =
false;
800 bool wordWrap =
false;
801 bool returnKeyStartsNewLine =
false;
802 bool popupMenuEnabled =
true;
803 bool selectAllTextWhenFocused =
false;
804 bool scrollbarVisible =
true;
805 bool wasFocused =
false;
806 bool keepCaretOnScreen =
true;
807 bool tabKeyUsed =
false;
808 bool menuActive =
false;
809 bool valueTextNeedsUpdating =
false;
810 bool consumeEscAndReturnKeys =
true;
811 bool underlineWhitespace =
true;
812 bool clicksOutsideDismissVirtualKeyboard =
false;
814 UndoManager undoManager;
816 Range<int> selection;
817 int leftIndent = 4, topIndent = 4;
818 unsigned int lastTransactionTime = 0;
819 Font currentFont { 14.0f };
820 mutable int totalNumChars = 0;
821 int caretPosition = 0;
822 OwnedArray<UniformTextSection> sections;
823 String textToShowWhenEmpty;
824 Colour colourForTextWhenEmpty;
826 OptionalScopedPointer<InputFilter> inputFilter;
828 VirtualKeyboardType keyboardType = TextInputTarget::textKeyboard;
829 float lineSpacing = 1.0f;
834 draggingSelectionStart,
838 DragType dragType = notDragging;
840 ListenerList<Listener> listeners;
841 Array<Range<int>> underlinedSections;
843 void moveCaret (
int newCaretPos);
844 void moveCaretTo (
int newPosition,
bool isSelecting);
845 void recreateCaret();
846 void handleCommandMessage (
int)
override;
847 void coalesceSimilarSections();
848 void splitSection (
int sectionIndex,
int charToSplitAt);
849 void clearInternal (UndoManager*);
850 void insert (
const String&,
int insertIndex,
const Font&, Colour, UndoManager*,
int newCaretPos);
851 void reinsert (
int insertIndex,
const OwnedArray<UniformTextSection>&);
852 void remove (Range<int>, UndoManager*,
int caretPositionToMoveTo);
853 void getCharPosition (
int index, Point<float>&,
float& lineHeight)
const;
854 void updateCaretPosition();
855 void updateValueFromText();
856 void textWasChangedByValue();
857 int indexAtPosition (
float x,
float y)
const;
858 int findWordBreakAfter (
int position)
const;
859 int findWordBreakBefore (
int position)
const;
860 bool moveCaretWithTransaction (
int newPos,
bool selecting);
861 void drawContent (Graphics&);
863 int getWordWrapWidth()
const;
864 int getMaximumTextWidth()
const;
865 int getMaximumTextHeight()
const;
866 void timerCallbackInt();
868 void repaintText (Range<int>);
869 void scrollByLines (
int deltaLines);
870 bool undoOrRedo (
bool shouldUndo);
871 UndoManager* getUndoManager() noexcept;
872 void setSelection (Range<
int>) noexcept;
873 Point<
int> getTextOffset() const noexcept;
Holds a resizable array of primitive or copy-by-value objects.
Specifies a set of gaps to be left around the sides of a rectangle.
Represents a colour, also including a transparency value.
The base class for all JUCE user-interface objects.
FocusChangeType
Enumeration used by the focusGained() and focusLost() methods.
Represents a particular font, including its size, style, etc.
A graphics context, used for drawing a component or image.
Represents a type of justification to be used when positioning graphical items.
Represents a key press, including any modifier keys that are needed.
Contains position and status information about a mouse event.
A MouseListener can be registered with a component to receive callbacks about mouse events that happe...
A pair of (x, y) coordinates.
A general-purpose range object, that simply represents any linear range with a start and end point.
Maintains a set of rectangles as a complex region.
Manages a rectangle and allows geometric operations to be performed on it.
Base class for input filters that can be applied to a TextEditor to restrict the text that can be ent...
virtual String filterNewText(TextEditor &, const String &newInput)=0
This method is called whenever text is entered into the editor.
An input filter for a TextEditor that limits the length of text and/or the characters that it may con...
Receives callbacks from a TextEditor component when it changes.
virtual void textEditorTextChanged(TextEditor &)
Called when the user changes the text in some way.
virtual ~Listener()=default
Destructor.
virtual void textEditorFocusLost(TextEditor &)
Called when the text editor loses focus.
virtual void textEditorReturnKeyPressed(TextEditor &)
Called when the user presses the return key.
virtual void textEditorEscapeKeyPressed(TextEditor &)
Called when the user presses the escape key.
bool isWhitespaceUnderlined() const noexcept
Returns true if whitespace is underlined for underlined fonts.
bool getClicksOutsideDismissVirtualKeyboard() const
Returns true if the editor is configured to hide the virtual keyboard when the mouse is pressed on an...
ColourIds
A set of colour IDs to use to change the colour of various aspects of the editor.
InputFilter * getInputFilter() const noexcept
Returns the current InputFilter, as set by setInputFilter().
bool isTabKeyUsedAsCharacter() const
Returns true if the tab key is being used for input.
bool isPopupMenuEnabled() const noexcept
Returns true if the right-click menu is enabled.
void setWhitespaceUnderlined(bool shouldUnderlineWhitespace) noexcept
Sets whether whitespace should be underlined when the editor font is underlined.
bool getReturnKeyStartsNewLine() const
Returns the value set by setReturnKeyStartsNewLine().
Justification getJustificationType() const noexcept
Returns the type of justification, as set in setJustification().
const Font & getFont() const noexcept
Returns the font that's currently being used for new text.
std::function< void()> onFocusLost
You can assign a lambda to this callback object to have it called when the editor loses key focus.
std::function< void()> onEscapeKey
You can assign a lambda to this callback object to have it called when the escape key is pressed.
bool isPopupMenuCurrentlyActive() const noexcept
Returns true if a popup-menu is currently being displayed.
void setLineSpacing(float newLineSpacing) noexcept
Sets the line spacing of the TextEditor.
std::function< void()> onReturnKey
You can assign a lambda to this callback object to have it called when the return key is pressed.
int getLeftIndent() const noexcept
Returns the gap at the left edge of the editor.
float getLineSpacing() const noexcept
Returns the current line spacing of the TextEditor.
int getTopIndent() const noexcept
Returns the gap at the top edge of the editor.
Range< int > getHighlightedRegion() const override
Returns the range of characters that are selected.
bool areScrollbarsShown() const noexcept
Returns true if scrollbars are enabled.
juce_wchar getPasswordCharacter() const noexcept
Returns the current password character.
String getTextToShowWhenEmpty() const noexcept
Returns the text that will be shown when the text editor is empty.
std::function< void()> onTextChange
You can assign a lambda to this callback object to have it called when the text is changed.
void setKeyboardType(VirtualKeyboardType type) noexcept
Sets the type of virtual keyboard that should be displayed when this editor has focus.
An abstract base class which can be implemented by components that function as text editors.
VirtualKeyboardType
A set of possible on-screen keyboard types, for use in the getKeyboardType() method.
Represents a shared variant value.
wchar_t juce_wchar
A platform-independent 32-bit unicode character type.
constexpr Type jmax(Type a, Type b)
Returns the larger of two values.
@ textChanged
Indicates that the visible text of a text element has changed.
Contains status information about a mouse wheel event.
This abstract base class is implemented by LookAndFeel classes to provide TextEditor drawing function...