Browse Source

replace eventargs with simple options class.

pull/7781/head
Dan Walmsley 5 years ago
parent
commit
079c193a82
  1. 2
      src/Avalonia.Input/TextInput/ITextInputMethodImpl.cs
  2. 5
      src/Avalonia.Input/TextInput/InputMethodManager.cs
  3. 195
      src/Avalonia.Input/TextInput/TextInputOptions.cs
  4. 32
      src/Avalonia.Input/TextInput/TextInputOptionsQueryEventArgs.cs
  5. 2
      src/iOS/Avalonia.iOS/AvaloniaUIResponder.cs

2
src/Avalonia.Input/TextInput/ITextInputMethodImpl.cs

@ -4,7 +4,7 @@ namespace Avalonia.Input.TextInput
{
void SetActive(ITextInputMethodClient? client);
void SetCursorRect(Rect rect);
void SetOptions(TextInputOptionsQueryEventArgs options);
void SetOptions(TextInputOptions options);
void Reset();
}

5
src/Avalonia.Input/TextInput/InputMethodManager.cs

@ -40,10 +40,7 @@ namespace Avalonia.Input.TextInput
if (_focusedElement is AvaloniaObject target)
{
var options =
new TextInputOptionsQueryEventArgs { ContentType = TextInputOptions.GetContentType(target) };
_im?.SetOptions(options);
_im?.SetOptions(TextInputOptions.FromAvaloniaObject(target));
}
_transformTracker.SetVisual(_client?.TextViewVisual);

195
src/Avalonia.Input/TextInput/TextInputOptions.cs

@ -2,6 +2,21 @@ namespace Avalonia.Input.TextInput;
public class TextInputOptions
{
public static TextInputOptions FromAvaloniaObject(AvaloniaObject avaloniaObject)
{
var result = new TextInputOptions
{
ContentType = GetContentType(avaloniaObject),
Multiline = GetMultiline(avaloniaObject),
AutoCapitalization = GetAutoCapitalization(avaloniaObject),
IsSensitive = GetIsSensitive(avaloniaObject),
Lowercase = GetLowercase(avaloniaObject),
Uppercase = GetUppercase(avaloniaObject)
};
return result;
}
/// <summary>
/// Defines the <see cref="ContentType"/> property.
/// </summary>
@ -11,7 +26,6 @@ public class TextInputOptions
defaultValue: TextInputContentType.Normal,
inherits: true);
/// <summary>
/// Sets the value of the attached <see cref="ContentTypeProperty"/> on a control.
/// </summary>
@ -20,18 +34,185 @@ public class TextInputOptions
public static void SetContentType(AvaloniaObject avaloniaObject, TextInputContentType value)
{
avaloniaObject.SetValue(ContentTypeProperty, value);
}
/// <summary>
/// Gets the value of the attached <see cref="ContentTypeProperty"/> on a control.
/// Gets the value of the attached <see cref="ContentTypeProperty"/>.
/// </summary>
/// <param name="avaloniaObject">The control.</param>
/// <returns>The font family.</returns>
/// <param name="avaloniaObject">The target.</param>
/// <returns>TextInputContentType</returns>
public static TextInputContentType GetContentType(AvaloniaObject avaloniaObject)
{
return avaloniaObject.GetValue(ContentTypeProperty);
}
/// <summary>
/// The content type (mostly for determining the shape of the virtual keyboard)
/// </summary>
public TextInputContentType ContentType { get; set; }
/// <summary>
/// Defines the <see cref="Multiline"/> property.
/// </summary>
public static readonly AttachedProperty<bool> MultilineProperty =
AvaloniaProperty.RegisterAttached<TextInputOptions, AvaloniaObject, bool>(
"Multiline",
inherits: true);
/// <summary>
/// Sets the value of the attached <see cref="MultilineProperty"/> on a control.
/// </summary>
/// <param name="avaloniaObject">The control.</param>
/// <param name="value">The property value to set.</param>
public static void SetMultiline(AvaloniaObject avaloniaObject, bool value)
{
avaloniaObject.SetValue(MultilineProperty, value);
}
/// <summary>
/// Gets the value of the attached <see cref="MultilineProperty"/>.
/// </summary>
/// <param name="avaloniaObject">The target.</param>
/// <returns>true if multiline</returns>
public static bool GetMultiline(AvaloniaObject avaloniaObject)
{
return avaloniaObject.GetValue(MultilineProperty);
}
/// <summary>
/// Text is multiline
/// </summary>
public bool Multiline { get; set; }
/// <summary>
/// Defines the <see cref="Lowercase"/> property.
/// </summary>
public static readonly AttachedProperty<bool> LowercaseProperty =
AvaloniaProperty.RegisterAttached<TextInputOptions, AvaloniaObject, bool>(
"Lowercase",
inherits: true);
/// <summary>
/// Sets the value of the attached <see cref="LowercaseProperty"/> on a control.
/// </summary>
/// <param name="avaloniaObject">The control.</param>
/// <param name="value">The property value to set.</param>
public static void SetLowercase(AvaloniaObject avaloniaObject, bool value)
{
avaloniaObject.SetValue(LowercaseProperty, value);
}
/// <summary>
/// Gets the value of the attached <see cref="LowercaseProperty"/>.
/// </summary>
/// <param name="avaloniaObject">The target.</param>
/// <returns>true if Lowercase</returns>
public static bool GetLowercase(AvaloniaObject avaloniaObject)
{
return avaloniaObject.GetValue(LowercaseProperty);
}
/// <summary>
/// Text is in lower case
/// </summary>
public bool Lowercase { get; set; }
/// <summary>
/// Defines the <see cref="Uppercase"/> property.
/// </summary>
public static readonly AttachedProperty<bool> UppercaseProperty =
AvaloniaProperty.RegisterAttached<TextInputOptions, AvaloniaObject, bool>(
"Uppercase",
inherits: true);
/// <summary>
/// Sets the value of the attached <see cref="UppercaseProperty"/> on a control.
/// </summary>
/// <param name="avaloniaObject">The control.</param>
/// <param name="value">The property value to set.</param>
public static void SetUppercase(AvaloniaObject avaloniaObject, bool value)
{
avaloniaObject.SetValue(UppercaseProperty, value);
}
/// <summary>
/// Gets the value of the attached <see cref="UppercaseProperty"/>.
/// </summary>
/// <param name="avaloniaObject">The target.</param>
/// <returns>true if Uppercase</returns>
public static bool GetUppercase(AvaloniaObject avaloniaObject)
{
return avaloniaObject.GetValue(UppercaseProperty);
}
/// <summary>
/// Text is in upper case
/// </summary>
public bool Uppercase { get; set; }
/// <summary>
/// Defines the <see cref="AutoCapitalization"/> property.
/// </summary>
public static readonly AttachedProperty<bool> AutoCapitalizationProperty =
AvaloniaProperty.RegisterAttached<TextInputOptions, AvaloniaObject, bool>(
"AutoCapitalization",
inherits: true);
/// <summary>
/// Sets the value of the attached <see cref="AutoCapitalizationProperty"/> on a control.
/// </summary>
/// <param name="avaloniaObject">The control.</param>
/// <param name="value">The property value to set.</param>
public static void SetAutoCapitalization(AvaloniaObject avaloniaObject, bool value)
{
avaloniaObject.SetValue(AutoCapitalizationProperty, value);
}
/// <summary>
/// Gets the value of the attached <see cref="AutoCapitalizationProperty"/>.
/// </summary>
/// <param name="avaloniaObject">The target.</param>
/// <returns>true if AutoCapitalization</returns>
public static bool GetAutoCapitalization(AvaloniaObject avaloniaObject)
{
return avaloniaObject.GetValue(AutoCapitalizationProperty);
}
/// <summary>
/// Automatically capitalize letters at the start of the sentence
/// </summary>
public bool AutoCapitalization { get; set; }
/// <summary>
/// Defines the <see cref="IsSensitive"/> property.
/// </summary>
public static readonly AttachedProperty<bool> IsSensitiveProperty =
AvaloniaProperty.RegisterAttached<TextInputOptions, AvaloniaObject, bool>(
"IsSensitive",
inherits: true);
/// <summary>
/// Sets the value of the attached <see cref="IsSensitiveProperty"/> on a control.
/// </summary>
/// <param name="avaloniaObject">The control.</param>
/// <param name="value">The property value to set.</param>
public static void SetIsSensitive(AvaloniaObject avaloniaObject, bool value)
{
avaloniaObject.SetValue(IsSensitiveProperty, value);
}
/// <summary>
/// Gets the value of the attached <see cref="IsSensitiveProperty"/>.
/// </summary>
/// <param name="avaloniaObject">The target.</param>
/// <returns>true if IsSensitive</returns>
public static bool GetIsSensitive(AvaloniaObject avaloniaObject)
{
return avaloniaObject.GetValue(IsSensitiveProperty);
}
/// <summary>
/// Text contains sensitive data like card numbers and should not be stored
/// </summary>
public bool IsSensitive { get; set; }
}

32
src/Avalonia.Input/TextInput/TextInputOptionsQueryEventArgs.cs

@ -1,32 +0,0 @@
using Avalonia.Interactivity;
namespace Avalonia.Input.TextInput
{
public class TextInputOptionsQueryEventArgs : RoutedEventArgs
{
/// <summary>
/// The content type (mostly for determining the shape of the virtual keyboard)
/// </summary>
public TextInputContentType ContentType { get; set; }
/// <summary>
/// Text is multiline
/// </summary>
public bool Multiline { get; set; }
/// <summary>
/// Text is in lower case
/// </summary>
public bool Lowercase { get; set; }
/// <summary>
/// Text is in upper case
/// </summary>
public bool Uppercase { get; set; }
/// <summary>
/// Automatically capitalize letters at the start of the sentence
/// </summary>
public bool AutoCapitalization { get; set; }
/// <summary>
/// Text contains sensitive data like card numbers and should not be stored
/// </summary>
public bool IsSensitive { get; set; }
}
}

2
src/iOS/Avalonia.iOS/AvaloniaUIResponder.cs

@ -80,7 +80,7 @@ public partial class AvaloniaView : ITextInputMethodImpl
}
void ITextInputMethodImpl.SetOptions(TextInputOptionsQueryEventArgs options)
void ITextInputMethodImpl.SetOptions(TextInputOptions options)
{
switch (options.ContentType)
{

Loading…
Cancel
Save