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.

773 lines
31KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #pragma once
  20. //==============================================================================
  21. /**
  22. An editable text box.
  23. A TextEditor can either be in single- or multi-line mode, and supports mixed
  24. fonts and colours.
  25. @see TextEditor::Listener, Label
  26. */
  27. class JUCE_API TextEditor : public Component,
  28. public TextInputTarget,
  29. public SettableTooltipClient
  30. {
  31. public:
  32. //==============================================================================
  33. /** Creates a new, empty text editor.
  34. @param componentName the name to pass to the component for it to use as its name
  35. @param passwordCharacter if this is not zero, this character will be used as a replacement
  36. for all characters that are drawn on screen - e.g. to create
  37. a password-style textbox containing circular blobs instead of text,
  38. you could set this value to 0x25cf, which is the unicode character
  39. for a black splodge (not all fonts include this, though), or 0x2022,
  40. which is a bullet (probably the best choice for linux).
  41. */
  42. explicit TextEditor (const String& componentName = String(),
  43. juce_wchar passwordCharacter = 0);
  44. /** Destructor. */
  45. ~TextEditor();
  46. //==============================================================================
  47. /** Puts the editor into either multi- or single-line mode.
  48. By default, the editor will be in single-line mode, so use this if you need a multi-line
  49. editor.
  50. See also the setReturnKeyStartsNewLine() method, which will also need to be turned
  51. on if you want a multi-line editor with line-breaks.
  52. @see isMultiLine, setReturnKeyStartsNewLine
  53. */
  54. void setMultiLine (bool shouldBeMultiLine,
  55. bool shouldWordWrap = true);
  56. /** Returns true if the editor is in multi-line mode. */
  57. bool isMultiLine() const;
  58. //==============================================================================
  59. /** Changes the behaviour of the return key.
  60. If set to true, the return key will insert a new-line into the text; if false
  61. it will trigger a call to the TextEditor::Listener::textEditorReturnKeyPressed()
  62. method. By default this is set to false, and when true it will only insert
  63. new-lines when in multi-line mode (see setMultiLine()).
  64. */
  65. void setReturnKeyStartsNewLine (bool shouldStartNewLine);
  66. /** Returns the value set by setReturnKeyStartsNewLine().
  67. See setReturnKeyStartsNewLine() for more info.
  68. */
  69. bool getReturnKeyStartsNewLine() const { return returnKeyStartsNewLine; }
  70. /** Indicates whether the tab key should be accepted and used to input a tab character,
  71. or whether it gets ignored.
  72. By default the tab key is ignored, so that it can be used to switch keyboard focus
  73. between components.
  74. */
  75. void setTabKeyUsedAsCharacter (bool shouldTabKeyBeUsed);
  76. /** Returns true if the tab key is being used for input.
  77. @see setTabKeyUsedAsCharacter
  78. */
  79. bool isTabKeyUsedAsCharacter() const { return tabKeyUsed; }
  80. /** This can be used to change whether escape and return keypress events are
  81. propagated up to the parent component.
  82. The default here is true, meaning that these events are not allowed to reach the
  83. parent, but you may want to allow them through so that they can trigger other
  84. actions, e.g. closing a dialog box, etc.
  85. */
  86. void setEscapeAndReturnKeysConsumed (bool shouldBeConsumed) noexcept;
  87. //==============================================================================
  88. /** Changes the editor to read-only mode.
  89. By default, the text editor is not read-only. If you're making it read-only, you
  90. might also want to call setCaretVisible (false) to get rid of the caret.
  91. The text can still be highlighted and copied when in read-only mode.
  92. @see isReadOnly, setCaretVisible
  93. */
  94. void setReadOnly (bool shouldBeReadOnly);
  95. /** Returns true if the editor is in read-only mode. */
  96. bool isReadOnly() const noexcept;
  97. //==============================================================================
  98. /** Makes the caret visible or invisible.
  99. By default the caret is visible.
  100. @see setCaretColour, setCaretPosition
  101. */
  102. void setCaretVisible (bool shouldBeVisible);
  103. /** Returns true if the caret is enabled.
  104. @see setCaretVisible
  105. */
  106. bool isCaretVisible() const noexcept { return caretVisible && ! isReadOnly(); }
  107. //==============================================================================
  108. /** Enables/disables a vertical scrollbar.
  109. (This only applies when in multi-line mode). When the text gets too long to fit
  110. in the component, a scrollbar can appear to allow it to be scrolled. Even when
  111. this is enabled, the scrollbar will be hidden unless it's needed.
  112. By default the scrollbar is enabled.
  113. */
  114. void setScrollbarsShown (bool shouldBeEnabled);
  115. /** Returns true if scrollbars are enabled.
  116. @see setScrollbarsShown
  117. */
  118. bool areScrollbarsShown() const noexcept { return scrollbarVisible; }
  119. /** Changes the password character used to disguise the text.
  120. @param passwordCharacter if this is not zero, this character will be used as a replacement
  121. for all characters that are drawn on screen - e.g. to create
  122. a password-style textbox containing circular blobs instead of text,
  123. you could set this value to 0x25cf, which is the unicode character
  124. for a black splodge (not all fonts include this, though), or 0x2022,
  125. which is a bullet (probably the best choice for linux).
  126. */
  127. void setPasswordCharacter (juce_wchar passwordCharacter);
  128. /** Returns the current password character.
  129. @see setPasswordCharacter
  130. */
  131. juce_wchar getPasswordCharacter() const noexcept { return passwordCharacter; }
  132. //==============================================================================
  133. /** Allows a right-click menu to appear for the editor.
  134. (This defaults to being enabled).
  135. If enabled, right-clicking (or command-clicking on the Mac) will pop up a menu
  136. of options such as cut/copy/paste, undo/redo, etc.
  137. */
  138. void setPopupMenuEnabled (bool menuEnabled);
  139. /** Returns true if the right-click menu is enabled.
  140. @see setPopupMenuEnabled
  141. */
  142. bool isPopupMenuEnabled() const noexcept { return popupMenuEnabled; }
  143. /** Returns true if a popup-menu is currently being displayed. */
  144. bool isPopupMenuCurrentlyActive() const noexcept { return menuActive; }
  145. //==============================================================================
  146. /** A set of colour IDs to use to change the colour of various aspects of the editor.
  147. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  148. methods.
  149. NB: You can also set the caret colour using CaretComponent::caretColourId
  150. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  151. */
  152. enum ColourIds
  153. {
  154. backgroundColourId = 0x1000200, /**< The colour to use for the text component's background - this can be
  155. transparent if necessary. */
  156. textColourId = 0x1000201, /**< The colour that will be used when text is added to the editor. Note
  157. that because the editor can contain multiple colours, calling this
  158. method won't change the colour of existing text - to do that, use
  159. the applyColourToAllText() method */
  160. highlightColourId = 0x1000202, /**< The colour with which to fill the background of highlighted sections of
  161. the text - this can be transparent if you don't want to show any
  162. highlighting.*/
  163. highlightedTextColourId = 0x1000203, /**< The colour with which to draw the text in highlighted sections. */
  164. outlineColourId = 0x1000205, /**< If this is non-transparent, it will be used to draw a box around
  165. the edge of the component. */
  166. focusedOutlineColourId = 0x1000206, /**< If this is non-transparent, it will be used to draw a box around
  167. the edge of the component when it has focus. */
  168. shadowColourId = 0x1000207, /**< If this is non-transparent, it'll be used to draw an inner shadow
  169. around the edge of the editor. */
  170. };
  171. //==============================================================================
  172. /** Sets the font to use for newly added text.
  173. This will change the font that will be used next time any text is added or entered
  174. into the editor. It won't change the font of any existing text - to do that, use
  175. applyFontToAllText() instead.
  176. @see applyFontToAllText
  177. */
  178. void setFont (const Font& newFont);
  179. /** Applies a font to all the text in the editor.
  180. If the changeCurrentFont argument is true then this will also set the
  181. new font as the font to be used for any new text that's added.
  182. @see setFont
  183. */
  184. void applyFontToAllText (const Font& newFont, bool changeCurrentFont = true);
  185. /** Returns the font that's currently being used for new text.
  186. @see setFont
  187. */
  188. const Font& getFont() const noexcept { return currentFont; }
  189. /** Applies a colour to all the text in the editor.
  190. If the changeCurrentTextColour argument is true then this will also set the
  191. new colour as the colour to be used for any new text that's added.
  192. */
  193. void applyColourToAllText (const Colour& newColour, bool changeCurrentTextColour = true);
  194. //==============================================================================
  195. /** If set to true, focusing on the editor will highlight all its text.
  196. (Set to false by default).
  197. This is useful for boxes where you expect the user to re-enter all the
  198. text when they focus on the component, rather than editing what's already there.
  199. */
  200. void setSelectAllWhenFocused (bool shouldSelectAll);
  201. /** When the text editor is empty, it can be set to display a message.
  202. This is handy for things like telling the user what to type in the box - the
  203. string is only displayed, it's not taken to actually be the contents of
  204. the editor.
  205. */
  206. void setTextToShowWhenEmpty (const String& text, Colour colourToUse);
  207. //==============================================================================
  208. /** Changes the size of the scrollbars that are used.
  209. Handy if you need smaller scrollbars for a small text box.
  210. */
  211. void setScrollBarThickness (int newThicknessPixels);
  212. //==============================================================================
  213. /**
  214. Receives callbacks from a TextEditor component when it changes.
  215. @see TextEditor::addListener
  216. */
  217. class JUCE_API Listener
  218. {
  219. public:
  220. /** Destructor. */
  221. virtual ~Listener() {}
  222. /** Called when the user changes the text in some way. */
  223. virtual void textEditorTextChanged (TextEditor&) {}
  224. /** Called when the user presses the return key. */
  225. virtual void textEditorReturnKeyPressed (TextEditor&) {}
  226. /** Called when the user presses the escape key. */
  227. virtual void textEditorEscapeKeyPressed (TextEditor&) {}
  228. /** Called when the text editor loses focus. */
  229. virtual void textEditorFocusLost (TextEditor&) {}
  230. };
  231. /** Registers a listener to be told when things happen to the text.
  232. @see removeListener
  233. */
  234. void addListener (Listener* newListener);
  235. /** Deregisters a listener.
  236. @see addListener
  237. */
  238. void removeListener (Listener* listenerToRemove);
  239. //==============================================================================
  240. /** Returns the entire contents of the editor. */
  241. String getText() const;
  242. /** Returns a section of the contents of the editor. */
  243. String getTextInRange (const Range<int>& textRange) const override;
  244. /** Returns true if there are no characters in the editor.
  245. This is far more efficient than calling getText().isEmpty().
  246. */
  247. bool isEmpty() const;
  248. /** Sets the entire content of the editor.
  249. This will clear the editor and insert the given text (using the current text colour
  250. and font). You can set the current text colour using
  251. @code setColour (TextEditor::textColourId, ...);
  252. @endcode
  253. @param newText the text to add
  254. @param sendTextChangeMessage if true, this will cause a change message to
  255. be sent to all the listeners.
  256. @see insertTextAtCaret
  257. */
  258. void setText (const String& newText,
  259. bool sendTextChangeMessage = true);
  260. /** Returns a Value object that can be used to get or set the text.
  261. Bear in mind that this operate quite slowly if your text box contains large
  262. amounts of text, as it needs to dynamically build the string that's involved.
  263. It's best used for small text boxes.
  264. */
  265. Value& getTextValue();
  266. /** Inserts some text at the current caret position.
  267. If a section of the text is highlighted, it will be replaced by
  268. this string, otherwise it will be inserted.
  269. To delete a section of text, you can use setHighlightedRegion() to
  270. highlight it, and call insertTextAtCaret (String()).
  271. @see setCaretPosition, getCaretPosition, setHighlightedRegion
  272. */
  273. void insertTextAtCaret (const String& textToInsert) override;
  274. /** Deletes all the text from the editor. */
  275. void clear();
  276. /** Deletes the currently selected region.
  277. This doesn't copy the deleted section to the clipboard - if you need to do that, call copy() first.
  278. @see copy, paste, SystemClipboard
  279. */
  280. void cut();
  281. /** Copies the currently selected region to the clipboard.
  282. @see cut, paste, SystemClipboard
  283. */
  284. void copy();
  285. /** Pastes the contents of the clipboard into the editor at the caret position.
  286. @see cut, copy, SystemClipboard
  287. */
  288. void paste();
  289. //==============================================================================
  290. /** Returns the current index of the caret.
  291. @see setCaretPosition
  292. */
  293. int getCaretPosition() const;
  294. /** Moves the caret to be in front of a given character.
  295. @see getCaretPosition, moveCaretToEnd
  296. */
  297. void setCaretPosition (int newIndex);
  298. /** Attempts to scroll the text editor so that the caret ends up at
  299. a specified position.
  300. This won't affect the caret's position within the text, it tries to scroll
  301. the entire editor vertically and horizontally so that the caret is sitting
  302. at the given position (relative to the top-left of this component).
  303. Depending on the amount of text available, it might not be possible to
  304. scroll far enough for the caret to reach this exact position, but it
  305. will go as far as it can in that direction.
  306. */
  307. void scrollEditorToPositionCaret (int desiredCaretX, int desiredCaretY);
  308. /** Get the graphical position of the caret.
  309. The rectangle returned is relative to the component's top-left corner.
  310. @see scrollEditorToPositionCaret
  311. */
  312. Rectangle<int> getCaretRectangle() override;
  313. /** Selects a section of the text. */
  314. void setHighlightedRegion (const Range<int>& newSelection) override;
  315. /** Returns the range of characters that are selected.
  316. If nothing is selected, this will return an empty range.
  317. @see setHighlightedRegion
  318. */
  319. Range<int> getHighlightedRegion() const override { return selection; }
  320. /** Returns the section of text that is currently selected. */
  321. String getHighlightedText() const;
  322. /** Finds the index of the character at a given position.
  323. The coordinates are relative to the component's top-left.
  324. */
  325. int getTextIndexAt (int x, int y);
  326. /** Counts the number of characters in the text.
  327. This is quicker than getting the text as a string if you just need to know
  328. the length.
  329. */
  330. int getTotalNumChars() const;
  331. /** Returns the total width of the text, as it is currently laid-out.
  332. This may be larger than the size of the TextEditor, and can change when
  333. the TextEditor is resized or the text changes.
  334. */
  335. int getTextWidth() const;
  336. /** Returns the maximum height of the text, as it is currently laid-out.
  337. This may be larger than the size of the TextEditor, and can change when
  338. the TextEditor is resized or the text changes.
  339. */
  340. int getTextHeight() const;
  341. /** Changes the size of the gap at the top and left-edge of the editor.
  342. By default there's a gap of 4 pixels.
  343. */
  344. void setIndents (int newLeftIndent, int newTopIndent);
  345. /** Changes the size of border left around the edge of the component.
  346. @see getBorder
  347. */
  348. void setBorder (const BorderSize<int>& border);
  349. /** Returns the size of border around the edge of the component.
  350. @see setBorder
  351. */
  352. BorderSize<int> getBorder() const;
  353. /** Used to disable the auto-scrolling which keeps the caret visible.
  354. If true (the default), the editor will scroll when the caret moves offscreen. If
  355. set to false, it won't.
  356. */
  357. void setScrollToShowCursor (bool shouldScrollToShowCaret);
  358. /** Sets the line spacing of the TextEditor.
  359. The default (and minimum) value is 1.0 and values > 1.0 will increase the line spacing as a
  360. multiple of the line height e.g. for double-spacing call this method with an argument of 2.0.
  361. */
  362. void setLineSpacing (float newLineSpacing) noexcept { lineSpacing = jmax (1.0f, newLineSpacing); }
  363. /** Returns the current line spacing of the TextEditor. */
  364. float getLineSpacing() const noexcept { return lineSpacing; }
  365. //==============================================================================
  366. void moveCaretToEnd();
  367. bool moveCaretLeft (bool moveInWholeWordSteps, bool selecting);
  368. bool moveCaretRight (bool moveInWholeWordSteps, bool selecting);
  369. bool moveCaretUp (bool selecting);
  370. bool moveCaretDown (bool selecting);
  371. bool pageUp (bool selecting);
  372. bool pageDown (bool selecting);
  373. bool scrollDown();
  374. bool scrollUp();
  375. bool moveCaretToTop (bool selecting);
  376. bool moveCaretToStartOfLine (bool selecting);
  377. bool moveCaretToEnd (bool selecting);
  378. bool moveCaretToEndOfLine (bool selecting);
  379. bool deleteBackwards (bool moveInWholeWordSteps);
  380. bool deleteForwards (bool moveInWholeWordSteps);
  381. bool copyToClipboard();
  382. bool cutToClipboard();
  383. bool pasteFromClipboard();
  384. bool selectAll();
  385. bool undo();
  386. bool redo();
  387. //==============================================================================
  388. /** This adds the items to the popup menu.
  389. By default it adds the cut/copy/paste items, but you can override this if
  390. you need to replace these with your own items.
  391. If you want to add your own items to the existing ones, you can override this,
  392. call the base class's addPopupMenuItems() method, then append your own items.
  393. When the menu has been shown, performPopupMenuAction() will be called to
  394. perform the item that the user has chosen.
  395. The default menu items will be added using item IDs from the
  396. StandardApplicationCommandIDs namespace.
  397. If this was triggered by a mouse-click, the mouseClickEvent parameter will be
  398. a pointer to the info about it, or may be null if the menu is being triggered
  399. by some other means.
  400. @see performPopupMenuAction, setPopupMenuEnabled, isPopupMenuEnabled
  401. */
  402. virtual void addPopupMenuItems (PopupMenu& menuToAddTo,
  403. const MouseEvent* mouseClickEvent);
  404. /** This is called to perform one of the items that was shown on the popup menu.
  405. If you've overridden addPopupMenuItems(), you should also override this
  406. to perform the actions that you've added.
  407. If you've overridden addPopupMenuItems() but have still left the default items
  408. on the menu, remember to call the superclass's performPopupMenuAction()
  409. so that it can perform the default actions if that's what the user clicked on.
  410. @see addPopupMenuItems, setPopupMenuEnabled, isPopupMenuEnabled
  411. */
  412. virtual void performPopupMenuAction (int menuItemID);
  413. //==============================================================================
  414. /** Base class for input filters that can be applied to a TextEditor to restrict
  415. the text that can be entered.
  416. */
  417. class JUCE_API InputFilter
  418. {
  419. public:
  420. InputFilter() {}
  421. virtual ~InputFilter() {}
  422. /** This method is called whenever text is entered into the editor.
  423. An implementation of this class should should check the input string,
  424. and return an edited version of it that should be used.
  425. */
  426. virtual String filterNewText (TextEditor&, const String& newInput) = 0;
  427. };
  428. /** An input filter for a TextEditor that limits the length of text and/or the
  429. characters that it may contain.
  430. */
  431. class JUCE_API LengthAndCharacterRestriction : public InputFilter
  432. {
  433. public:
  434. /** Creates a filter that limits the length of text, and/or the characters that it can contain.
  435. @param maxNumChars if this is > 0, it sets a maximum length limit; if <= 0, no
  436. limit is set
  437. @param allowedCharacters if this is non-empty, then only characters that occur in
  438. this string are allowed to be entered into the editor.
  439. */
  440. LengthAndCharacterRestriction (int maxNumChars, const String& allowedCharacters);
  441. String filterNewText (TextEditor&, const String&) override;
  442. private:
  443. String allowedCharacters;
  444. int maxLength;
  445. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LengthAndCharacterRestriction)
  446. };
  447. /** Sets an input filter that should be applied to this editor.
  448. The filter can be nullptr, to remove any existing filters.
  449. If takeOwnership is true, then the filter will be owned and deleted by the editor
  450. when no longer needed.
  451. */
  452. void setInputFilter (InputFilter* newFilter, bool takeOwnership);
  453. /** Returns the current InputFilter, as set by setInputFilter(). */
  454. InputFilter* getInputFilter() const noexcept { return inputFilter; }
  455. /** Sets limits on the characters that can be entered.
  456. This is just a shortcut that passes an instance of the LengthAndCharacterRestriction
  457. class to setInputFilter().
  458. @param maxTextLength if this is > 0, it sets a maximum length limit; if 0, no
  459. limit is set
  460. @param allowedCharacters if this is non-empty, then only characters that occur in
  461. this string are allowed to be entered into the editor.
  462. */
  463. void setInputRestrictions (int maxTextLength,
  464. const String& allowedCharacters = String());
  465. void setKeyboardType (VirtualKeyboardType type) noexcept { keyboardType = type; }
  466. //==============================================================================
  467. /** This abstract base class is implemented by LookAndFeel classes to provide
  468. TextEditor drawing functionality.
  469. */
  470. struct JUCE_API LookAndFeelMethods
  471. {
  472. virtual ~LookAndFeelMethods() {}
  473. virtual void fillTextEditorBackground (Graphics&, int width, int height, TextEditor&) = 0;
  474. virtual void drawTextEditorOutline (Graphics&, int width, int height, TextEditor&) = 0;
  475. virtual CaretComponent* createCaretComponent (Component* keyFocusOwner) = 0;
  476. };
  477. //==============================================================================
  478. /** @internal */
  479. void paint (Graphics&) override;
  480. /** @internal */
  481. void paintOverChildren (Graphics&) override;
  482. /** @internal */
  483. void mouseDown (const MouseEvent&) override;
  484. /** @internal */
  485. void mouseUp (const MouseEvent&) override;
  486. /** @internal */
  487. void mouseDrag (const MouseEvent&) override;
  488. /** @internal */
  489. void mouseDoubleClick (const MouseEvent&) override;
  490. /** @internal */
  491. void mouseWheelMove (const MouseEvent&, const MouseWheelDetails&) override;
  492. /** @internal */
  493. bool keyPressed (const KeyPress&) override;
  494. /** @internal */
  495. bool keyStateChanged (bool) override;
  496. /** @internal */
  497. void focusGained (FocusChangeType) override;
  498. /** @internal */
  499. void focusLost (FocusChangeType) override;
  500. /** @internal */
  501. void resized() override;
  502. /** @internal */
  503. void enablementChanged() override;
  504. /** @internal */
  505. void colourChanged() override;
  506. /** @internal */
  507. void lookAndFeelChanged() override;
  508. /** @internal */
  509. void parentHierarchyChanged() override;
  510. /** @internal */
  511. bool isTextInputActive() const override;
  512. /** @internal */
  513. void setTemporaryUnderlining (const Array<Range<int> >&) override;
  514. /** @internal */
  515. VirtualKeyboardType getKeyboardType() override { return keyboardType; }
  516. protected:
  517. //==============================================================================
  518. /** Scrolls the minimum distance needed to get the caret into view. */
  519. void scrollToMakeSureCursorIsVisible();
  520. /** Used internally to dispatch a text-change message. */
  521. void textChanged();
  522. /** Begins a new transaction in the UndoManager. */
  523. void newTransaction();
  524. /** Can be overridden to intercept return key presses directly */
  525. virtual void returnPressed();
  526. /** Can be overridden to intercept escape key presses directly */
  527. virtual void escapePressed();
  528. private:
  529. //==============================================================================
  530. class Iterator;
  531. JUCE_PUBLIC_IN_DLL_BUILD (class UniformTextSection)
  532. class TextHolderComponent;
  533. class InsertAction;
  534. class RemoveAction;
  535. friend class InsertAction;
  536. friend class RemoveAction;
  537. ScopedPointer<Viewport> viewport;
  538. TextHolderComponent* textHolder;
  539. BorderSize<int> borderSize { 1, 1, 1, 3 };
  540. bool readOnly = false;
  541. bool caretVisible = true;
  542. bool multiline = false;
  543. bool wordWrap = false;
  544. bool returnKeyStartsNewLine = false;
  545. bool popupMenuEnabled = true;
  546. bool selectAllTextWhenFocused = false;
  547. bool scrollbarVisible = true;
  548. bool wasFocused = false;
  549. bool keepCaretOnScreen = true;
  550. bool tabKeyUsed = false;
  551. bool menuActive = false;
  552. bool valueTextNeedsUpdating = false;
  553. bool consumeEscAndReturnKeys = true;
  554. UndoManager undoManager;
  555. ScopedPointer<CaretComponent> caret;
  556. Range<int> selection;
  557. int leftIndent = 4, topIndent = 4;
  558. unsigned int lastTransactionTime = 0;
  559. Font currentFont { 14.0f };
  560. mutable int totalNumChars = 0;
  561. int caretPosition = 0;
  562. OwnedArray<UniformTextSection> sections;
  563. String textToShowWhenEmpty;
  564. Colour colourForTextWhenEmpty;
  565. juce_wchar passwordCharacter;
  566. OptionalScopedPointer<InputFilter> inputFilter;
  567. Value textValue;
  568. VirtualKeyboardType keyboardType;
  569. float lineSpacing = 1.0f;
  570. enum
  571. {
  572. notDragging,
  573. draggingSelectionStart,
  574. draggingSelectionEnd
  575. } dragType;
  576. ListenerList<Listener> listeners;
  577. Array<Range<int> > underlinedSections;
  578. void moveCaret (int newCaretPos);
  579. void moveCaretTo (int newPosition, bool isSelecting);
  580. void recreateCaret();
  581. void handleCommandMessage (int) override;
  582. void coalesceSimilarSections();
  583. void splitSection (int sectionIndex, int charToSplitAt);
  584. void clearInternal (UndoManager*);
  585. void insert (const String&, int insertIndex, const Font&, const Colour, UndoManager*, int newCaretPos);
  586. void reinsert (int insertIndex, const OwnedArray<UniformTextSection>&);
  587. void remove (Range<int> range, UndoManager*, int caretPositionToMoveTo);
  588. void getCharPosition (int index, float& x, float& y, float& lineHeight) const;
  589. void updateCaretPosition();
  590. void updateValueFromText();
  591. void textWasChangedByValue();
  592. int indexAtPosition (float x, float y);
  593. int findWordBreakAfter (int position) const;
  594. int findWordBreakBefore (int position) const;
  595. bool moveCaretWithTransaction (int newPos, bool selecting);
  596. friend class TextHolderComponent;
  597. friend class TextEditorViewport;
  598. void drawContent (Graphics&);
  599. void updateTextHolderSize();
  600. float getWordWrapWidth() const;
  601. void timerCallbackInt();
  602. void repaintText (Range<int>);
  603. void scrollByLines (int deltaLines);
  604. bool undoOrRedo (bool shouldUndo);
  605. UndoManager* getUndoManager() noexcept;
  606. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TextEditor)
  607. };
  608. /** This typedef is just for compatibility with old code - newer code should use the TextEditor::Listener class directly. */
  609. typedef TextEditor::Listener TextEditorListener;