using Avalonia.Input.Platform;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Avalonia.Reactive;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Utils;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Media;
using Avalonia.Metadata;
using Avalonia.Data;
using Avalonia.Layout;
using Avalonia.Utilities;
using Avalonia.Controls.Metadata;
using Avalonia.Media.TextFormatting;
using Avalonia.Automation.Peers;
using Avalonia.Media.TextFormatting.Unicode;
using Avalonia.Threading;
namespace Avalonia.Controls
{
///
/// Represents a control that can be used to display or edit unformatted text.
///
[TemplatePart("PART_TextPresenter", typeof(TextPresenter), IsRequired = true)]
[TemplatePart("PART_ScrollViewer", typeof(ScrollViewer))]
[PseudoClasses(":empty")]
public class TextBox : TemplatedControl, UndoRedoHelper.IUndoRedoHost
{
///
/// Gets a platform-specific for the Cut action
///
public static KeyGesture? CutGesture => Application.Current?.PlatformSettings?.HotkeyConfiguration.Cut.FirstOrDefault();
///
/// Gets a platform-specific for the Copy action
///
public static KeyGesture? CopyGesture => Application.Current?.PlatformSettings?.HotkeyConfiguration.Copy.FirstOrDefault();
///
/// Gets a platform-specific for the Paste action
///
public static KeyGesture? PasteGesture => Application.Current?.PlatformSettings?.HotkeyConfiguration.Paste.FirstOrDefault();
///
/// Defines the property
///
public static readonly StyledProperty IsInactiveSelectionHighlightEnabledProperty =
AvaloniaProperty.Register(nameof(IsInactiveSelectionHighlightEnabled), defaultValue: true);
///
/// Defines the property
///
public static readonly StyledProperty ClearSelectionOnLostFocusProperty =
AvaloniaProperty.Register(nameof(ClearSelectionOnLostFocus), defaultValue: true);
///
/// Defines the property
///
public static readonly StyledProperty AcceptsReturnProperty =
AvaloniaProperty.Register(nameof(AcceptsReturn));
///
/// Defines the property
///
public static readonly StyledProperty AcceptsTabProperty =
AvaloniaProperty.Register(nameof(AcceptsTab));
///
/// Defines the property
///
public static readonly StyledProperty CaretIndexProperty =
AvaloniaProperty.Register(nameof(CaretIndex),
coerce: CoerceCaretIndex);
///
/// Defines the property
///
public static readonly StyledProperty IsReadOnlyProperty =
AvaloniaProperty.Register(nameof(IsReadOnly));
///
/// Defines the property
///
public static readonly StyledProperty PasswordCharProperty =
AvaloniaProperty.Register(nameof(PasswordChar));
///
/// Defines the property
///
public static readonly StyledProperty SelectionBrushProperty =
AvaloniaProperty.Register(nameof(SelectionBrush));
///
/// Defines the property
///
public static readonly StyledProperty SelectionForegroundBrushProperty =
AvaloniaProperty.Register(nameof(SelectionForegroundBrush));
///
/// Defines the property
///
public static readonly StyledProperty CaretBrushProperty =
AvaloniaProperty.Register(nameof(CaretBrush));
///
/// Defines the property
///
public static readonly StyledProperty CaretBlinkIntervalProperty =
AvaloniaProperty.Register(nameof(CaretBlinkInterval), defaultValue: TimeSpan.FromMilliseconds(500));
///
/// Defines the property
///
public static readonly StyledProperty SelectionStartProperty =
AvaloniaProperty.Register(nameof(SelectionStart),
coerce: CoerceCaretIndex);
///
/// Defines the property
///
public static readonly StyledProperty SelectionEndProperty =
AvaloniaProperty.Register(nameof(SelectionEnd),
coerce: CoerceCaretIndex);
///
/// Defines the property
///
public static readonly StyledProperty MaxLengthProperty =
AvaloniaProperty.Register(nameof(MaxLength));
///
/// Defines the property
///
public static readonly StyledProperty MaxLinesProperty =
AvaloniaProperty.Register(nameof(MaxLines));
///
/// Defines the property
///
public static readonly StyledProperty MinLinesProperty =
AvaloniaProperty.Register(nameof(MinLines));
///
/// Defines the property
///
public static readonly StyledProperty TextProperty =
TextBlock.TextProperty.AddOwner(new(
coerce: CoerceText,
defaultBindingMode: BindingMode.TwoWay,
enableDataValidation: true));
///
/// Defines the property
///
public static readonly StyledProperty TextAlignmentProperty =
TextBlock.TextAlignmentProperty.AddOwner();
///
/// Defines the property.
///
public static readonly StyledProperty HorizontalContentAlignmentProperty =
ContentControl.HorizontalContentAlignmentProperty.AddOwner();
///
/// Defines the property.
///
public static readonly StyledProperty VerticalContentAlignmentProperty =
ContentControl.VerticalContentAlignmentProperty.AddOwner();
public static readonly StyledProperty TextWrappingProperty =
TextBlock.TextWrappingProperty.AddOwner();
///
/// Defines see property.
///
public static readonly StyledProperty LineHeightProperty =
TextBlock.LineHeightProperty.AddOwner(new(defaultValue: double.NaN));
///
/// Defines the property.
///
public static readonly StyledProperty PlaceholderTextProperty =
AvaloniaProperty.Register(nameof(PlaceholderText));
///
/// Defines the property.
///
[Obsolete("Use PlaceholderTextProperty instead.", false)]
[System.Diagnostics.CodeAnalysis.SuppressMessage("AvaloniaProperty", "AVP1022",
Justification = "Obsolete property alias for backward compatibility.")]
public static readonly StyledProperty WatermarkProperty = PlaceholderTextProperty;
///
/// Defines the property.
///
public static readonly StyledProperty UseFloatingPlaceholderProperty =
AvaloniaProperty.Register(nameof(UseFloatingPlaceholder));
///
/// Defines the property.
///
[Obsolete("Use UseFloatingPlaceholderProperty instead.", false)]
[System.Diagnostics.CodeAnalysis.SuppressMessage("AvaloniaProperty", "AVP1022",
Justification = "Obsolete property alias for backward compatibility.")]
public static readonly StyledProperty UseFloatingWatermarkProperty = UseFloatingPlaceholderProperty;
///
/// Defines the property.
///
public static readonly StyledProperty PlaceholderForegroundProperty =
AvaloniaProperty.Register(nameof(PlaceholderForeground));
///
/// Defines the property.
///
[Obsolete("Use PlaceholderForegroundProperty instead.", false)]
[System.Diagnostics.CodeAnalysis.SuppressMessage("AvaloniaProperty", "AVP1022",
Justification = "Obsolete property alias for backward compatibility.")]
public static readonly StyledProperty WatermarkForegroundProperty = PlaceholderForegroundProperty;
///
/// Defines the property
///
public static readonly StyledProperty NewLineProperty =
AvaloniaProperty.Register(nameof(NewLine), Environment.NewLine);
///
/// Defines the property
///
public static readonly StyledProperty