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.

121 lines
4.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  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 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. /**
  21. An abstract base class which can be implemented by components that function as
  22. text editors.
  23. This class allows different types of text editor component to provide a uniform
  24. interface, which can be used by things like OS-specific input methods, on-screen
  25. keyboards, etc.
  26. @tags{GUI}
  27. */
  28. class JUCE_API TextInputTarget
  29. {
  30. public:
  31. //==============================================================================
  32. /** */
  33. TextInputTarget() = default;
  34. /** Destructor. */
  35. virtual ~TextInputTarget() = default;
  36. /** Returns true if this input target is currently accepting input.
  37. For example, a text editor might return false if it's in read-only mode.
  38. */
  39. virtual bool isTextInputActive() const = 0;
  40. /** Returns the extents of the selected text region, or an empty range if
  41. nothing is selected,
  42. */
  43. virtual Range<int> getHighlightedRegion() const = 0;
  44. /** Sets the currently-selected text region. */
  45. virtual void setHighlightedRegion (const Range<int>& newRange) = 0;
  46. /** Sets a number of temporarily underlined sections.
  47. This is needed by MS Windows input method UI.
  48. */
  49. virtual void setTemporaryUnderlining (const Array<Range<int>>& underlinedRegions) = 0;
  50. /** Returns a specified sub-section of the text. */
  51. virtual String getTextInRange (const Range<int>& range) const = 0;
  52. /** Inserts some text, overwriting the selected text region, if there is one. */
  53. virtual void insertTextAtCaret (const String& textToInsert) = 0;
  54. /** Returns the current index of the caret. */
  55. virtual int getCaretPosition() const = 0;
  56. /** Returns the position of the caret, relative to the component's origin. */
  57. Rectangle<int> getCaretRectangle() const { return getCaretRectangleForCharIndex (getCaretPosition()); }
  58. /** Returns the bounding box of the character at the given index. */
  59. virtual Rectangle<int> getCaretRectangleForCharIndex (int characterIndex) const = 0;
  60. /** Returns the total number of codepoints in the string. */
  61. virtual int getTotalNumChars() const = 0;
  62. /** Returns the index closest to the given point.
  63. This is the location where the cursor might be placed after clicking at the given
  64. point in a text field.
  65. */
  66. virtual int getCharIndexForPoint (Point<int> point) const = 0;
  67. /** Returns the bounding box for a range of text in the editor. As the range may span
  68. multiple lines, this method returns a RectangleList.
  69. The bounds are relative to the component's top-left and may extend beyond the bounds
  70. of the component if the text is long and word wrapping is disabled.
  71. */
  72. virtual RectangleList<int> getTextBounds (Range<int> textRange) const = 0;
  73. /** A set of possible on-screen keyboard types, for use in the
  74. getKeyboardType() method.
  75. */
  76. enum VirtualKeyboardType
  77. {
  78. textKeyboard = 0,
  79. numericKeyboard,
  80. decimalKeyboard,
  81. urlKeyboard,
  82. emailAddressKeyboard,
  83. phoneNumberKeyboard,
  84. passwordKeyboard
  85. };
  86. /** Returns the target's preference for the type of keyboard that would be most appropriate.
  87. This may be ignored, depending on the capabilities of the OS.
  88. */
  89. virtual VirtualKeyboardType getKeyboardType() { return textKeyboard; }
  90. };
  91. } // namespace juce