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.

juce_TextEditor.h 30KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  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. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  149. */
  150. enum ColourIds
  151. {
  152. backgroundColourId = 0x1000200, /**< The colour to use for the text component's background - this can be
  153. transparent if necessary. */
  154. textColourId = 0x1000201, /**< The colour that will be used when text is added to the editor. Note
  155. that because the editor can contain multiple colours, calling this
  156. method won't change the colour of existing text - to do that, call
  157. applyFontToAllText() after calling this method.*/
  158. highlightColourId = 0x1000202, /**< The colour with which to fill the background of highlighted sections of
  159. the text - this can be transparent if you don't want to show any
  160. highlighting.*/
  161. highlightedTextColourId = 0x1000203, /**< The colour with which to draw the text in highlighted sections. */
  162. outlineColourId = 0x1000205, /**< If this is non-transparent, it will be used to draw a box around
  163. the edge of the component. */
  164. focusedOutlineColourId = 0x1000206, /**< If this is non-transparent, it will be used to draw a box around
  165. the edge of the component when it has focus. */
  166. shadowColourId = 0x1000207, /**< If this is non-transparent, it'll be used to draw an inner shadow
  167. around the edge of the editor. */
  168. };
  169. //==============================================================================
  170. /** Sets the font to use for newly added text.
  171. This will change the font that will be used next time any text is added or entered
  172. into the editor. It won't change the font of any existing text - to do that, use
  173. applyFontToAllText() instead.
  174. @see applyFontToAllText
  175. */
  176. void setFont (const Font& newFont);
  177. /** Applies a font to all the text in the editor.
  178. This will also set the current font to use for any new text that's added.
  179. @see setFont
  180. */
  181. void applyFontToAllText (const Font& newFont);
  182. /** Returns the font that's currently being used for new text.
  183. @see setFont
  184. */
  185. const Font& getFont() const noexcept { return currentFont; }
  186. //==============================================================================
  187. /** If set to true, focusing on the editor will highlight all its text.
  188. (Set to false by default).
  189. This is useful for boxes where you expect the user to re-enter all the
  190. text when they focus on the component, rather than editing what's already there.
  191. */
  192. void setSelectAllWhenFocused (bool shouldSelectAll);
  193. /** When the text editor is empty, it can be set to display a message.
  194. This is handy for things like telling the user what to type in the box - the
  195. string is only displayed, it's not taken to actually be the contents of
  196. the editor.
  197. */
  198. void setTextToShowWhenEmpty (const String& text, Colour colourToUse);
  199. //==============================================================================
  200. /** Changes the size of the scrollbars that are used.
  201. Handy if you need smaller scrollbars for a small text box.
  202. */
  203. void setScrollBarThickness (int newThicknessPixels);
  204. //==============================================================================
  205. /**
  206. Receives callbacks from a TextEditor component when it changes.
  207. @see TextEditor::addListener
  208. */
  209. class JUCE_API Listener
  210. {
  211. public:
  212. /** Destructor. */
  213. virtual ~Listener() {}
  214. /** Called when the user changes the text in some way. */
  215. virtual void textEditorTextChanged (TextEditor&) {}
  216. /** Called when the user presses the return key. */
  217. virtual void textEditorReturnKeyPressed (TextEditor&) {}
  218. /** Called when the user presses the escape key. */
  219. virtual void textEditorEscapeKeyPressed (TextEditor&) {}
  220. /** Called when the text editor loses focus. */
  221. virtual void textEditorFocusLost (TextEditor&) {}
  222. };
  223. /** Registers a listener to be told when things happen to the text.
  224. @see removeListener
  225. */
  226. void addListener (Listener* newListener);
  227. /** Deregisters a listener.
  228. @see addListener
  229. */
  230. void removeListener (Listener* listenerToRemove);
  231. //==============================================================================
  232. /** Returns the entire contents of the editor. */
  233. String getText() const;
  234. /** Returns a section of the contents of the editor. */
  235. String getTextInRange (const Range<int>& textRange) const override;
  236. /** Returns true if there are no characters in the editor.
  237. This is far more efficient than calling getText().isEmpty().
  238. */
  239. bool isEmpty() const;
  240. /** Sets the entire content of the editor.
  241. This will clear the editor and insert the given text (using the current text colour
  242. and font). You can set the current text colour using
  243. @code setColour (TextEditor::textColourId, ...);
  244. @endcode
  245. @param newText the text to add
  246. @param sendTextChangeMessage if true, this will cause a change message to
  247. be sent to all the listeners.
  248. @see insertText
  249. */
  250. void setText (const String& newText,
  251. bool sendTextChangeMessage = true);
  252. /** Returns a Value object that can be used to get or set the text.
  253. Bear in mind that this operate quite slowly if your text box contains large
  254. amounts of text, as it needs to dynamically build the string that's involved.
  255. It's best used for small text boxes.
  256. */
  257. Value& getTextValue();
  258. /** Inserts some text at the current caret position.
  259. If a section of the text is highlighted, it will be replaced by
  260. this string, otherwise it will be inserted.
  261. To delete a section of text, you can use setHighlightedRegion() to
  262. highlight it, and call insertTextAtCursor (String::empty).
  263. @see setCaretPosition, getCaretPosition, setHighlightedRegion
  264. */
  265. void insertTextAtCaret (const String& textToInsert) override;
  266. /** Deletes all the text from the editor. */
  267. void clear();
  268. /** Deletes the currently selected region.
  269. This doesn't copy the deleted section to the clipboard - if you need to do that, call copy() first.
  270. @see copy, paste, SystemClipboard
  271. */
  272. void cut();
  273. /** Copies the currently selected region to the clipboard.
  274. @see cut, paste, SystemClipboard
  275. */
  276. void copy();
  277. /** Pastes the contents of the clipboard into the editor at the caret position.
  278. @see cut, copy, SystemClipboard
  279. */
  280. void paste();
  281. //==============================================================================
  282. /** Returns the current index of the caret.
  283. @see setCaretPosition
  284. */
  285. int getCaretPosition() const;
  286. /** Moves the caret to be in front of a given character.
  287. @see getCaretPosition, moveCaretToEnd
  288. */
  289. void setCaretPosition (int newIndex);
  290. /** Attempts to scroll the text editor so that the caret ends up at
  291. a specified position.
  292. This won't affect the caret's position within the text, it tries to scroll
  293. the entire editor vertically and horizontally so that the caret is sitting
  294. at the given position (relative to the top-left of this component).
  295. Depending on the amount of text available, it might not be possible to
  296. scroll far enough for the caret to reach this exact position, but it
  297. will go as far as it can in that direction.
  298. */
  299. void scrollEditorToPositionCaret (int desiredCaretX, int desiredCaretY);
  300. /** Get the graphical position of the caret.
  301. The rectangle returned is relative to the component's top-left corner.
  302. @see scrollEditorToPositionCaret
  303. */
  304. Rectangle<int> getCaretRectangle() override;
  305. /** Selects a section of the text. */
  306. void setHighlightedRegion (const Range<int>& newSelection) override;
  307. /** Returns the range of characters that are selected.
  308. If nothing is selected, this will return an empty range.
  309. @see setHighlightedRegion
  310. */
  311. Range<int> getHighlightedRegion() const override { return selection; }
  312. /** Returns the section of text that is currently selected. */
  313. String getHighlightedText() const;
  314. /** Finds the index of the character at a given position.
  315. The coordinates are relative to the component's top-left.
  316. */
  317. int getTextIndexAt (int x, int y);
  318. /** Counts the number of characters in the text.
  319. This is quicker than getting the text as a string if you just need to know
  320. the length.
  321. */
  322. int getTotalNumChars() const;
  323. /** Returns the total width of the text, as it is currently laid-out.
  324. This may be larger than the size of the TextEditor, and can change when
  325. the TextEditor is resized or the text changes.
  326. */
  327. int getTextWidth() const;
  328. /** Returns the maximum height of the text, as it is currently laid-out.
  329. This may be larger than the size of the TextEditor, and can change when
  330. the TextEditor is resized or the text changes.
  331. */
  332. int getTextHeight() const;
  333. /** Changes the size of the gap at the top and left-edge of the editor.
  334. By default there's a gap of 4 pixels.
  335. */
  336. void setIndents (int newLeftIndent, int newTopIndent);
  337. /** Changes the size of border left around the edge of the component.
  338. @see getBorder
  339. */
  340. void setBorder (const BorderSize<int>& border);
  341. /** Returns the size of border around the edge of the component.
  342. @see setBorder
  343. */
  344. BorderSize<int> getBorder() const;
  345. /** Used to disable the auto-scrolling which keeps the caret visible.
  346. If true (the default), the editor will scroll when the caret moves offscreen. If
  347. set to false, it won't.
  348. */
  349. void setScrollToShowCursor (bool shouldScrollToShowCaret);
  350. //==============================================================================
  351. void moveCaretToEnd();
  352. bool moveCaretLeft (bool moveInWholeWordSteps, bool selecting);
  353. bool moveCaretRight (bool moveInWholeWordSteps, bool selecting);
  354. bool moveCaretUp (bool selecting);
  355. bool moveCaretDown (bool selecting);
  356. bool pageUp (bool selecting);
  357. bool pageDown (bool selecting);
  358. bool scrollDown();
  359. bool scrollUp();
  360. bool moveCaretToTop (bool selecting);
  361. bool moveCaretToStartOfLine (bool selecting);
  362. bool moveCaretToEnd (bool selecting);
  363. bool moveCaretToEndOfLine (bool selecting);
  364. bool deleteBackwards (bool moveInWholeWordSteps);
  365. bool deleteForwards (bool moveInWholeWordSteps);
  366. bool copyToClipboard();
  367. bool cutToClipboard();
  368. bool pasteFromClipboard();
  369. bool selectAll();
  370. bool undo();
  371. bool redo();
  372. //==============================================================================
  373. /** This adds the items to the popup menu.
  374. By default it adds the cut/copy/paste items, but you can override this if
  375. you need to replace these with your own items.
  376. If you want to add your own items to the existing ones, you can override this,
  377. call the base class's addPopupMenuItems() method, then append your own items.
  378. When the menu has been shown, performPopupMenuAction() will be called to
  379. perform the item that the user has chosen.
  380. The default menu items will be added using item IDs from the
  381. StandardApplicationCommandIDs namespace.
  382. If this was triggered by a mouse-click, the mouseClickEvent parameter will be
  383. a pointer to the info about it, or may be null if the menu is being triggered
  384. by some other means.
  385. @see performPopupMenuAction, setPopupMenuEnabled, isPopupMenuEnabled
  386. */
  387. virtual void addPopupMenuItems (PopupMenu& menuToAddTo,
  388. const MouseEvent* mouseClickEvent);
  389. /** This is called to perform one of the items that was shown on the popup menu.
  390. If you've overridden addPopupMenuItems(), you should also override this
  391. to perform the actions that you've added.
  392. If you've overridden addPopupMenuItems() but have still left the default items
  393. on the menu, remember to call the superclass's performPopupMenuAction()
  394. so that it can perform the default actions if that's what the user clicked on.
  395. @see addPopupMenuItems, setPopupMenuEnabled, isPopupMenuEnabled
  396. */
  397. virtual void performPopupMenuAction (int menuItemID);
  398. //==============================================================================
  399. /** Base class for input filters that can be applied to a TextEditor to restrict
  400. the text that can be entered.
  401. */
  402. class JUCE_API InputFilter
  403. {
  404. public:
  405. InputFilter() {}
  406. virtual ~InputFilter() {}
  407. /** This method is called whenever text is entered into the editor.
  408. An implementation of this class should should check the input string,
  409. and return an edited version of it that should be used.
  410. */
  411. virtual String filterNewText (TextEditor&, const String& newInput) = 0;
  412. };
  413. /** An input filter for a TextEditor that limits the length of text and/or the
  414. characters that it may contain.
  415. */
  416. class JUCE_API LengthAndCharacterRestriction : public InputFilter
  417. {
  418. public:
  419. /** Creates a filter that limits the length of text, and/or the characters that it can contain.
  420. @param maxNumChars if this is > 0, it sets a maximum length limit; if <= 0, no
  421. limit is set
  422. @param allowedCharacters if this is non-empty, then only characters that occur in
  423. this string are allowed to be entered into the editor.
  424. */
  425. LengthAndCharacterRestriction (int maxNumChars, const String& allowedCharacters);
  426. private:
  427. String allowedCharacters;
  428. int maxLength;
  429. String filterNewText (TextEditor&, const String&) override;
  430. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LengthAndCharacterRestriction)
  431. };
  432. /** Sets an input filter that should be applied to this editor.
  433. The filter can be nullptr, to remove any existing filters.
  434. If takeOwnership is true, then the filter will be owned and deleted by the editor
  435. when no longer needed.
  436. */
  437. void setInputFilter (InputFilter* newFilter, bool takeOwnership);
  438. /** Sets limits on the characters that can be entered.
  439. This is just a shortcut that passes an instance of the LengthAndCharacterRestriction
  440. class to setInputFilter().
  441. @param maxTextLength if this is > 0, it sets a maximum length limit; if 0, no
  442. limit is set
  443. @param allowedCharacters if this is non-empty, then only characters that occur in
  444. this string are allowed to be entered into the editor.
  445. */
  446. void setInputRestrictions (int maxTextLength,
  447. const String& allowedCharacters = String::empty);
  448. //==============================================================================
  449. /** This abstract base class is implemented by LookAndFeel classes to provide
  450. TextEditor drawing functionality.
  451. */
  452. struct JUCE_API LookAndFeelMethods
  453. {
  454. virtual ~LookAndFeelMethods() {}
  455. virtual void fillTextEditorBackground (Graphics&, int width, int height, TextEditor&) = 0;
  456. virtual void drawTextEditorOutline (Graphics&, int width, int height, TextEditor&) = 0;
  457. virtual CaretComponent* createCaretComponent (Component* keyFocusOwner) = 0;
  458. };
  459. //==============================================================================
  460. /** @internal */
  461. void paint (Graphics&) override;
  462. /** @internal */
  463. void paintOverChildren (Graphics&) override;
  464. /** @internal */
  465. void mouseDown (const MouseEvent&) override;
  466. /** @internal */
  467. void mouseUp (const MouseEvent&) override;
  468. /** @internal */
  469. void mouseDrag (const MouseEvent&) override;
  470. /** @internal */
  471. void mouseDoubleClick (const MouseEvent&) override;
  472. /** @internal */
  473. void mouseWheelMove (const MouseEvent&, const MouseWheelDetails&) override;
  474. /** @internal */
  475. bool keyPressed (const KeyPress&) override;
  476. /** @internal */
  477. bool keyStateChanged (bool) override;
  478. /** @internal */
  479. void focusGained (FocusChangeType) override;
  480. /** @internal */
  481. void focusLost (FocusChangeType) override;
  482. /** @internal */
  483. void resized() override;
  484. /** @internal */
  485. void enablementChanged() override;
  486. /** @internal */
  487. void colourChanged() override;
  488. /** @internal */
  489. void lookAndFeelChanged() override;
  490. /** @internal */
  491. bool isTextInputActive() const override;
  492. /** @internal */
  493. void setTemporaryUnderlining (const Array <Range<int> >&) override;
  494. protected:
  495. //==============================================================================
  496. /** Scrolls the minimum distance needed to get the caret into view. */
  497. void scrollToMakeSureCursorIsVisible();
  498. /** Used internally to dispatch a text-change message. */
  499. void textChanged();
  500. /** Begins a new transaction in the UndoManager. */
  501. void newTransaction();
  502. /** Can be overridden to intercept return key presses directly */
  503. virtual void returnPressed();
  504. /** Can be overridden to intercept escape key presses directly */
  505. virtual void escapePressed();
  506. private:
  507. //==============================================================================
  508. class Iterator;
  509. JUCE_PUBLIC_IN_DLL_BUILD (class UniformTextSection)
  510. class TextHolderComponent;
  511. class InsertAction;
  512. class RemoveAction;
  513. friend class InsertAction;
  514. friend class RemoveAction;
  515. ScopedPointer<Viewport> viewport;
  516. TextHolderComponent* textHolder;
  517. BorderSize<int> borderSize;
  518. bool readOnly : 1;
  519. bool multiline : 1;
  520. bool wordWrap : 1;
  521. bool returnKeyStartsNewLine : 1;
  522. bool popupMenuEnabled : 1;
  523. bool selectAllTextWhenFocused : 1;
  524. bool scrollbarVisible : 1;
  525. bool wasFocused : 1;
  526. bool keepCaretOnScreen : 1;
  527. bool tabKeyUsed : 1;
  528. bool menuActive : 1;
  529. bool valueTextNeedsUpdating : 1;
  530. bool consumeEscAndReturnKeys : 1;
  531. UndoManager undoManager;
  532. ScopedPointer<CaretComponent> caret;
  533. Range<int> selection;
  534. int leftIndent, topIndent;
  535. unsigned int lastTransactionTime;
  536. Font currentFont;
  537. mutable int totalNumChars;
  538. int caretPosition;
  539. OwnedArray<UniformTextSection> sections;
  540. String textToShowWhenEmpty;
  541. Colour colourForTextWhenEmpty;
  542. juce_wchar passwordCharacter;
  543. OptionalScopedPointer<InputFilter> inputFilter;
  544. Value textValue;
  545. enum
  546. {
  547. notDragging,
  548. draggingSelectionStart,
  549. draggingSelectionEnd
  550. } dragType;
  551. ListenerList <Listener> listeners;
  552. Array <Range<int> > underlinedSections;
  553. void moveCaret (int newCaretPos);
  554. void moveCaretTo (int newPosition, bool isSelecting);
  555. void handleCommandMessage (int) override;
  556. void coalesceSimilarSections();
  557. void splitSection (int sectionIndex, int charToSplitAt);
  558. void clearInternal (UndoManager*);
  559. void insert (const String&, int insertIndex, const Font&, const Colour, UndoManager*, int newCaretPos);
  560. void reinsert (int insertIndex, const OwnedArray<UniformTextSection>&);
  561. void remove (Range<int> range, UndoManager*, int caretPositionToMoveTo);
  562. void getCharPosition (int index, float& x, float& y, float& lineHeight) const;
  563. void updateCaretPosition();
  564. void updateValueFromText();
  565. void textWasChangedByValue();
  566. int indexAtPosition (float x, float y);
  567. int findWordBreakAfter (int position) const;
  568. int findWordBreakBefore (int position) const;
  569. bool moveCaretWithTransaction (int newPos, bool selecting);
  570. friend class TextHolderComponent;
  571. friend class TextEditorViewport;
  572. void drawContent (Graphics&);
  573. void updateTextHolderSize();
  574. float getWordWrapWidth() const;
  575. void timerCallbackInt();
  576. void repaintText (Range<int>);
  577. void scrollByLines (int deltaLines);
  578. bool undoOrRedo (bool shouldUndo);
  579. UndoManager* getUndoManager() noexcept;
  580. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TextEditor)
  581. };
  582. /** This typedef is just for compatibility with old code - newer code should use the TextEditor::Listener class directly. */
  583. typedef TextEditor::Listener TextEditorListener;
  584. #endif // JUCE_TEXTEDITOR_H_INCLUDED