Merge pull request #537 from irihitech/ipbox
Enable IME for IPv4Box on android.
This commit is contained in:
@@ -7,6 +7,7 @@ using Avalonia.Controls.Primitives;
|
|||||||
using Avalonia.Data;
|
using Avalonia.Data;
|
||||||
using Avalonia.Input;
|
using Avalonia.Input;
|
||||||
using Avalonia.Input.Platform;
|
using Avalonia.Input.Platform;
|
||||||
|
using Avalonia.Input.TextInput;
|
||||||
using Avalonia.Interactivity;
|
using Avalonia.Interactivity;
|
||||||
using Avalonia.Media;
|
using Avalonia.Media;
|
||||||
using Avalonia.Media.TextFormatting;
|
using Avalonia.Media.TextFormatting;
|
||||||
@@ -96,11 +97,15 @@ public class IPv4Box: TemplatedControl
|
|||||||
get => GetValue(InputModeProperty);
|
get => GetValue(InputModeProperty);
|
||||||
set => SetValue(InputModeProperty, value);
|
set => SetValue(InputModeProperty, value);
|
||||||
}
|
}
|
||||||
|
private readonly IPv4BoxInputMethodClient _imClient = new IPv4BoxInputMethodClient();
|
||||||
static IPv4Box()
|
static IPv4Box()
|
||||||
{
|
{
|
||||||
ShowLeadingZeroProperty.Changed.AddClassHandler<IPv4Box>((o, e) => o.OnFormatChange(e));
|
ShowLeadingZeroProperty.Changed.AddClassHandler<IPv4Box>((o, e) => o.OnFormatChange(e));
|
||||||
IPAddressProperty.Changed.AddClassHandler<IPv4Box>((o, e) => o.OnIPChanged(e));
|
IPAddressProperty.Changed.AddClassHandler<IPv4Box>((o, e) => o.OnIPChanged(e));
|
||||||
|
TextInputMethodClientRequestedEvent.AddClassHandler<IPv4Box>((tb, e) =>
|
||||||
|
{
|
||||||
|
e.Client = tb._imClient;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Overrides
|
#region Overrides
|
||||||
@@ -278,6 +283,7 @@ public class IPv4Box: TemplatedControl
|
|||||||
{
|
{
|
||||||
if (e.ClickCount == 1)
|
if (e.ClickCount == 1)
|
||||||
{
|
{
|
||||||
|
_imClient.SetPresenter(presenter);
|
||||||
presenter.ShowCaret();
|
presenter.ShowCaret();
|
||||||
_currentActivePresenter = presenter;
|
_currentActivePresenter = presenter;
|
||||||
var caretPosition = position.WithX(position.X - presenter.Bounds.X);
|
var caretPosition = position.WithX(position.X - presenter.Bounds.X);
|
||||||
31
src/Ursa/Controls/IPv4Box/IPv4BoxInputMethodClient.cs
Normal file
31
src/Ursa/Controls/IPv4Box/IPv4BoxInputMethodClient.cs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
using Avalonia;
|
||||||
|
using Avalonia.Controls.Presenters;
|
||||||
|
using Avalonia.Input.TextInput;
|
||||||
|
|
||||||
|
namespace Ursa.Controls;
|
||||||
|
|
||||||
|
public class IPv4BoxInputMethodClient:TextInputMethodClient
|
||||||
|
{
|
||||||
|
private TextPresenter? _presenter;
|
||||||
|
public override Visual TextViewVisual => _presenter;
|
||||||
|
public override bool SupportsPreedit => false;
|
||||||
|
public override bool SupportsSurroundingText => true;
|
||||||
|
|
||||||
|
public override string SurroundingText
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
}
|
||||||
|
public override Rect CursorRectangle { get; }
|
||||||
|
public override TextSelection Selection { get; set; }
|
||||||
|
private IPv4Box? _parent;
|
||||||
|
public void SetPresenter(TextPresenter? presenter)
|
||||||
|
{
|
||||||
|
this.RaiseTextViewVisualChanged();
|
||||||
|
this.RaiseCursorRectangleChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnParentPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
|
||||||
|
{
|
||||||
|
this.RaiseSelectionChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user