// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. namespace Microsoft.Maui.Platform.Linux.Services; /// /// Interface for Input Method Editor (IME) services. /// Provides support for complex text input methods like CJK languages. /// public interface IInputMethodService { /// /// Gets whether IME is currently active. /// bool IsActive { get; } /// /// Gets the current pre-edit (composition) text. /// string PreEditText { get; } /// /// Gets the cursor position within the pre-edit text. /// int PreEditCursorPosition { get; } /// /// Initializes the IME service for the given window. /// /// The native window handle. void Initialize(nint windowHandle); /// /// Sets focus to the specified input context. /// /// The input context to focus. void SetFocus(IInputContext? context); /// /// Sets the cursor location for candidate window positioning. /// /// X coordinate in screen space. /// Y coordinate in screen space. /// Width of the cursor area. /// Height of the cursor area. void SetCursorLocation(int x, int y, int width, int height); /// /// Processes a key event through the IME. /// /// The key code. /// Key modifiers. /// True for key press, false for key release. /// True if the IME handled the event. bool ProcessKeyEvent(uint keyCode, KeyModifiers modifiers, bool isKeyDown); /// /// Resets the IME state, canceling any composition. /// void Reset(); /// /// Shuts down the IME service. /// void Shutdown(); /// /// Event raised when text is committed from IME. /// event EventHandler? TextCommitted; /// /// Event raised when pre-edit (composition) text changes. /// event EventHandler? PreEditChanged; /// /// Event raised when pre-edit is completed or cancelled. /// event EventHandler? PreEditEnded; } /// /// Represents an input context that can receive IME input. /// public interface IInputContext { /// /// Gets or sets the current text content. /// string Text { get; set; } /// /// Gets or sets the cursor position. /// int CursorPosition { get; set; } /// /// Gets the selection start position. /// int SelectionStart { get; } /// /// Gets the selection length. /// int SelectionLength { get; } /// /// Called when text is committed from the IME. /// /// The committed text. void OnTextCommitted(string text); /// /// Called when pre-edit text changes. /// /// The current pre-edit text. /// Cursor position within pre-edit text. void OnPreEditChanged(string preEditText, int cursorPosition); /// /// Called when pre-edit mode ends. /// void OnPreEditEnded(); } /// /// Event args for text committed events. /// public class TextCommittedEventArgs : EventArgs { /// /// The committed text. /// public string Text { get; } public TextCommittedEventArgs(string text) { Text = text; } } /// /// Event args for pre-edit changed events. /// public class PreEditChangedEventArgs : EventArgs { /// /// The current pre-edit text. /// public string PreEditText { get; } /// /// Cursor position within the pre-edit text. /// public int CursorPosition { get; } /// /// Formatting attributes for the pre-edit text. /// public IReadOnlyList Attributes { get; } public PreEditChangedEventArgs(string preEditText, int cursorPosition, IReadOnlyList? attributes = null) { PreEditText = preEditText; CursorPosition = cursorPosition; Attributes = attributes ?? Array.Empty(); } } /// /// Represents formatting for a portion of pre-edit text. /// public class PreEditAttribute { /// /// Start position in the pre-edit text. /// public int Start { get; set; } /// /// Length of the attributed range. /// public int Length { get; set; } /// /// The attribute type. /// public PreEditAttributeType Type { get; set; } } /// /// Types of pre-edit text attributes. /// public enum PreEditAttributeType { /// /// Normal text (no special formatting). /// None, /// /// Underlined text (typical for composition). /// Underline, /// /// Highlighted/selected text. /// Highlighted, /// /// Reverse video (selected clause in some IMEs). /// Reverse } /// /// Key modifiers for IME processing. /// [Flags] public enum KeyModifiers { None = 0, Shift = 1 << 0, Control = 1 << 1, Alt = 1 << 2, Super = 1 << 3, CapsLock = 1 << 4, NumLock = 1 << 5 }