ITextInputMethodClient.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. using Avalonia.Media.TextFormatting;
  3. using Avalonia.VisualTree;
  4. namespace Avalonia.Input.TextInput
  5. {
  6. public interface ITextInputMethodClient
  7. {
  8. /// <summary>
  9. /// The cursor rectangle relative to the TextViewVisual
  10. /// </summary>
  11. Rect CursorRectangle { get; }
  12. /// <summary>
  13. /// Should be fired when cursor rectangle is changed inside the TextViewVisual
  14. /// </summary>
  15. event EventHandler? CursorRectangleChanged;
  16. /// <summary>
  17. /// The visual that's showing the text
  18. /// </summary>
  19. Visual TextViewVisual { get; }
  20. /// <summary>
  21. /// Should be fired when text-hosting visual is changed
  22. /// </summary>
  23. event EventHandler? TextViewVisualChanged;
  24. /// <summary>
  25. /// Indicates if TextViewVisual is capable of displaying non-committed input on the cursor position
  26. /// </summary>
  27. bool SupportsPreedit { get; }
  28. /// <summary>
  29. /// Sets the non-committed input string
  30. /// </summary>
  31. void SetPreeditText(string? text);
  32. /// <summary>
  33. /// Sets the current composing region. This doesn't remove the composing text from the commited text.
  34. /// </summary>
  35. void SetComposingRegion(TextRange? region);
  36. /// <summary>
  37. /// Indicates if text input client is capable of providing the text around the cursor
  38. /// </summary>
  39. bool SupportsSurroundingText { get; }
  40. /// <summary>
  41. /// Returns the text around the cursor, usually the current paragraph, the cursor position inside that text and selection start position
  42. /// </summary>
  43. TextInputMethodSurroundingText SurroundingText { get; }
  44. /// <summary>
  45. /// Should be fired when surrounding text changed
  46. /// </summary>
  47. event EventHandler? SurroundingTextChanged;
  48. /// <summary>
  49. /// Gets or sets a platform editable. Text and selection changes made in the editable are forwarded to the IM client.
  50. /// </summary>
  51. ITextEditable? TextEditable { get; set; }
  52. void SelectInSurroundingText(int start, int end);
  53. }
  54. public record struct TextInputMethodSurroundingText
  55. {
  56. public string Text { get; set; }
  57. public int CursorOffset { get; set; }
  58. public int AnchorOffset { get; set; }
  59. }
  60. }