diff --git a/src/Uno.UI.Runtime.Skia.Gtk/UI/Controls/GtkTextBoxView.cs b/src/Uno.UI.Runtime.Skia.Gtk/UI/Controls/GtkTextBoxView.cs index f24bcf7be475..bf595d72fcb9 100644 --- a/src/Uno.UI.Runtime.Skia.Gtk/UI/Controls/GtkTextBoxView.cs +++ b/src/Uno.UI.Runtime.Skia.Gtk/UI/Controls/GtkTextBoxView.cs @@ -106,6 +106,8 @@ public void SetPosition(double x, double y) } } + protected void RaisePaste(TextControlPasteEventArgs args) => Paste?.Invoke(this, args); + private void SetFont(TextBox textBox) { var fontDescription = new FontDescription diff --git a/src/Uno.UI.Runtime.Skia.Gtk/UI/Controls/MultilineTextBoxView.cs b/src/Uno.UI.Runtime.Skia.Gtk/UI/Controls/MultilineTextBoxView.cs index d97db1a2d0e6..0e33aa94d15d 100644 --- a/src/Uno.UI.Runtime.Skia.Gtk/UI/Controls/MultilineTextBoxView.cs +++ b/src/Uno.UI.Runtime.Skia.Gtk/UI/Controls/MultilineTextBoxView.cs @@ -3,6 +3,7 @@ using System; using Gtk; using Uno.Disposables; +using Uno.UI.Runtime.Skia.Gtk.UI.Controls; using Windows.UI.Xaml.Controls; namespace Uno.UI.Runtime.Skia.Gtk.UI.Xaml.Controls; @@ -12,14 +13,17 @@ internal class MultilineTextBoxView : GtkTextBoxView private const string MultilineHostCssClass = "textbox_multiline_host"; private readonly ScrolledWindow _scrolledWindow = new(); - private readonly TextView _textView = new(); + private readonly UnoGtkTextView _textView = new(); public MultilineTextBoxView() { _scrolledWindow.Add(_textView); _scrolledWindow.StyleContext.AddClass(MultilineHostCssClass); + _textView.Paste += OnPaste; } + private void OnPaste(object sender, TextControlPasteEventArgs args) => RaisePaste(args); + protected override Widget RootWidget => _scrolledWindow; protected override Widget InputWidget => _textView; diff --git a/src/Uno.UI.Runtime.Skia.Gtk/UI/Controls/SinglelineTextBoxView.cs b/src/Uno.UI.Runtime.Skia.Gtk/UI/Controls/SinglelineTextBoxView.cs index cb07435fe10f..c9437f2e0304 100644 --- a/src/Uno.UI.Runtime.Skia.Gtk/UI/Controls/SinglelineTextBoxView.cs +++ b/src/Uno.UI.Runtime.Skia.Gtk/UI/Controls/SinglelineTextBoxView.cs @@ -4,20 +4,24 @@ using System.Threading; using Gtk; using Uno.Disposables; +using Uno.UI.Runtime.Skia.Gtk.UI.Controls; using Windows.UI.Xaml.Controls; namespace Uno.UI.Runtime.Skia.Gtk.UI.Xaml.Controls; internal class SinglelineTextBoxView : GtkTextBoxView { - private readonly Entry _entry = new(); + private readonly UnoGtkEntry _entry = new(); private readonly bool _isPassword; public SinglelineTextBoxView(bool isPassword) { _isPassword = isPassword; + _entry.Paste += OnPaste; } + private void OnPaste(object sender, TextControlPasteEventArgs args) => RaisePaste(args); + protected override Widget InputWidget => _entry; protected override Widget RootWidget => _entry; diff --git a/src/Uno.UI.Runtime.Skia.Gtk/UI/Controls/UnoGtkEntry.cs b/src/Uno.UI.Runtime.Skia.Gtk/UI/Controls/UnoGtkEntry.cs new file mode 100644 index 000000000000..238930da1de5 --- /dev/null +++ b/src/Uno.UI.Runtime.Skia.Gtk/UI/Controls/UnoGtkEntry.cs @@ -0,0 +1,21 @@ +#nullable enable + +using Gtk; +using Windows.UI.Xaml.Controls; + +namespace Uno.UI.Runtime.Skia.Gtk.UI.Controls; + +internal class UnoGtkEntry : Entry +{ + protected override void OnClipboardPasted() + { + var args = new TextControlPasteEventArgs(); + Paste?.Invoke(this, args); + if (!args.Handled) + { + base.OnClipboardPasted(); + } + } + + public event TextControlPasteEventHandler? Paste; +} diff --git a/src/Uno.UI.Runtime.Skia.Gtk/UI/Controls/UnoGtkTextView.cs b/src/Uno.UI.Runtime.Skia.Gtk/UI/Controls/UnoGtkTextView.cs new file mode 100644 index 000000000000..2da636b07998 --- /dev/null +++ b/src/Uno.UI.Runtime.Skia.Gtk/UI/Controls/UnoGtkTextView.cs @@ -0,0 +1,20 @@ +#nullable enable + +using Gtk; +using Windows.UI.Xaml.Controls; + +namespace Uno.UI.Runtime.Skia.Gtk.UI.Controls; +internal class UnoGtkTextView : TextView +{ + protected override void OnPasteClipboard() + { + var args = new TextControlPasteEventArgs(); + Paste?.Invoke(this, args); + if (!args.Handled) + { + base.OnPasteClipboard(); + } + } + + public event TextControlPasteEventHandler? Paste; +} diff --git a/src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.cs b/src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.cs index c0d38abc44ca..8f4cccf6f226 100644 --- a/src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.cs +++ b/src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.cs @@ -70,7 +70,11 @@ public partial class TextBox : Control, IFrameworkTemplatePoolAware public event TypedEventHandler BeforeTextChanging; public event RoutedEventHandler SelectionChanged; #if __SKIA__ || __ANDROID__ || __CROSSRUNTIME__ || __IOS__ - public new event TextControlPasteEventHandler Paste; + public +#if ___IOS__ + new +#endif + event TextControlPasteEventHandler Paste; #endif internal void RaisePaste(TextControlPasteEventArgs args) => Paste?.Invoke(this, args);