using System;
namespace Avalonia.Input.TextInput
{
public abstract class TextInputMethodClient
{
///
/// Fires when the text view visual has changed
///
public event EventHandler? TextViewVisualChanged;
///
/// Fires when the cursor rectangle has changed
///
public event EventHandler? CursorRectangleChanged;
///
/// Fires when the surrounding text has changed
///
public event EventHandler? SurroundingTextChanged;
///
/// Fires when the selection has changed
///
public event EventHandler? SelectionChanged;
///
/// Fires when client wants to reset IME state
///
public event EventHandler? ResetRequested;
///
/// Fires when client requests the input panel be opened.
///
public event EventHandler? InputPaneActivationRequested;
///
/// The visual that's showing the text
///
public abstract Visual TextViewVisual { get; }
///
/// Indicates if TextViewVisual is capable of displaying non-committed input on the cursor position
///
public abstract bool SupportsPreedit { get; }
///
/// Indicates if text input client is capable of providing the text around the cursor
///
public abstract bool SupportsSurroundingText { get; }
///
/// Returns the text around the cursor, usually the current paragraph
///
public abstract string SurroundingText { get; }
///
/// Gets the cursor rectangle relative to the TextViewVisual
///
public abstract Rect CursorRectangle { get; }
///
/// Gets or sets the curent selection range within current surrounding text.
///
public abstract TextSelection Selection { get; set; }
///
/// Sets the non-committed input string
///
public virtual void SetPreeditText(string? preeditText) { }
///
/// Execute specific context menu actions
///
/// The to perform
public virtual void ExecuteContextMenuAction(ContextMenuAction action) { }
///
/// Sets the non-committed input string and cursor offset in that string
///
public virtual void SetPreeditText(string? preeditText, int? cursorPos)
{
SetPreeditText(preeditText);
}
//TODO12: remove
[Obsolete]
public virtual void ShowInputPanel()
{
RaiseInputPaneActivationRequested();
}
protected virtual void RaiseTextViewVisualChanged()
{
TextViewVisualChanged?.Invoke(this, EventArgs.Empty);
}
protected virtual void RaiseCursorRectangleChanged()
{
CursorRectangleChanged?.Invoke(this, EventArgs.Empty);
}
protected virtual void RaiseSurroundingTextChanged()
{
SurroundingTextChanged?.Invoke(this, EventArgs.Empty);
}
protected virtual void RaiseSelectionChanged()
{
SelectionChanged?.Invoke(this, EventArgs.Empty);
}
protected virtual void RaiseInputPaneActivationRequested()
{
InputPaneActivationRequested?.Invoke(this, EventArgs.Empty);
}
protected virtual void RequestReset()
{
ResetRequested?.Invoke(this, EventArgs.Empty);
}
}
public record struct TextSelection(int Start, int End);
public enum ContextMenuAction
{
Copy,
Cut,
Paste,
SelectAll
}
}