juce_TextInputTarget.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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_TEXTINPUTTARGET_H_INCLUDED
  18. #define JUCE_TEXTINPUTTARGET_H_INCLUDED
  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. */
  27. class JUCE_API TextInputTarget
  28. {
  29. public:
  30. //==============================================================================
  31. /** */
  32. TextInputTarget() {}
  33. /** Destructor. */
  34. virtual ~TextInputTarget() {}
  35. /** Returns true if this input target is currently accepting input.
  36. For example, a text editor might return false if it's in read-only mode.
  37. */
  38. virtual bool isTextInputActive() const = 0;
  39. /** Returns the extents of the selected text region, or an empty range if
  40. nothing is selected,
  41. */
  42. virtual Range<int> getHighlightedRegion() const = 0;
  43. /** Sets the currently-selected text region. */
  44. virtual void setHighlightedRegion (const Range<int>& newRange) = 0;
  45. /** Sets a number of temporarily underlined sections.
  46. This is needed by MS Windows input method UI.
  47. */
  48. virtual void setTemporaryUnderlining (const Array <Range<int> >& underlinedRegions) = 0;
  49. /** Returns a specified sub-section of the text. */
  50. virtual String getTextInRange (const Range<int>& range) const = 0;
  51. /** Inserts some text, overwriting the selected text region, if there is one. */
  52. virtual void insertTextAtCaret (const String& textToInsert) = 0;
  53. /** Returns the position of the caret, relative to the component's origin. */
  54. virtual Rectangle<int> getCaretRectangle() = 0;
  55. /** A set of possible on-screen keyboard types, for use in the
  56. getKeyboardType() method.
  57. */
  58. enum VirtualKeyboardType
  59. {
  60. textKeyboard = 0,
  61. numericKeyboard,
  62. urlKeyboard,
  63. emailAddressKeyboard,
  64. phoneNumberKeyboard
  65. };
  66. /** Returns the target's preference for the type of keyboard that would be most appropriate.
  67. This may be ignored, depending on the capabilities of the OS.
  68. */
  69. virtual VirtualKeyboardType getKeyboardType() { return textKeyboard; }
  70. };
  71. #endif // JUCE_TEXTINPUTTARGET_H_INCLUDED