Audio plugin host https://kx.studio/carla
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.

749 lines
30KB

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