TextInputMethodClient.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System;
  2. namespace Avalonia.Input.TextInput
  3. {
  4. public abstract class TextInputMethodClient
  5. {
  6. /// <summary>
  7. /// Fires when the text view visual has changed
  8. /// </summary>
  9. public event EventHandler? TextViewVisualChanged;
  10. /// <summary>
  11. /// Fires when the cursor rectangle has changed
  12. /// </summary>
  13. public event EventHandler? CursorRectangleChanged;
  14. /// <summary>
  15. /// Fires when the surrounding text has changed
  16. /// </summary>
  17. public event EventHandler? SurroundingTextChanged;
  18. /// <summary>
  19. /// Fires when the selection has changed
  20. /// </summary>
  21. public event EventHandler? SelectionChanged;
  22. /// <summary>
  23. /// The visual that's showing the text
  24. /// </summary>
  25. public abstract Visual TextViewVisual { get; }
  26. /// <summary>
  27. /// Indicates if TextViewVisual is capable of displaying non-committed input on the cursor position
  28. /// </summary>
  29. public abstract bool SupportsPreedit { get; }
  30. /// <summary>
  31. /// Indicates if text input client is capable of providing the text around the cursor
  32. /// </summary>
  33. public abstract bool SupportsSurroundingText { get; }
  34. /// <summary>
  35. /// Returns the text around the cursor, usually the current paragraph
  36. /// </summary>
  37. public abstract string SurroundingText { get; }
  38. /// <summary>
  39. /// Gets the cursor rectangle relative to the TextViewVisual
  40. /// </summary>
  41. public abstract Rect CursorRectangle { get; }
  42. /// <summary>
  43. /// Gets or sets the curent selection range within current surrounding text.
  44. /// </summary>
  45. public abstract TextSelection Selection { get; set; }
  46. /// <summary>
  47. /// Sets the non-committed input string
  48. /// </summary>
  49. public virtual void SetPreeditText(string? preeditText) { }
  50. protected virtual void OnTextViewVisualChanged(Visual? oldValue, Visual? newValue)
  51. {
  52. TextViewVisualChanged?.Invoke(this, EventArgs.Empty);
  53. }
  54. protected virtual void OnCursorRectangleChanged()
  55. {
  56. CursorRectangleChanged?.Invoke(this, EventArgs.Empty);
  57. }
  58. protected virtual void OnSurroundingTextChanged()
  59. {
  60. SurroundingTextChanged?.Invoke(this, EventArgs.Empty);
  61. }
  62. protected virtual void OnSelectionChanged()
  63. {
  64. SelectionChanged?.Invoke(this, EventArgs.Empty);
  65. }
  66. }
  67. public record struct TextSelection(int Start, int End);
  68. }