Skip to content

Commit

Permalink
feat: Support for TextBox.Paste and PasswordBox.Paste on GTK
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Oct 18, 2023
1 parent d174ff9 commit e58e5bc
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/Uno.UI.Runtime.Skia.Gtk/UI/Controls/GtkTextBoxView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 21 additions & 0 deletions src/Uno.UI.Runtime.Skia.Gtk/UI/Controls/UnoGtkEntry.cs
Original file line number Diff line number Diff line change
@@ -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;
}
20 changes: 20 additions & 0 deletions src/Uno.UI.Runtime.Skia.Gtk/UI/Controls/UnoGtkTextView.cs
Original file line number Diff line number Diff line change
@@ -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;
}
6 changes: 5 additions & 1 deletion src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ public partial class TextBox : Control, IFrameworkTemplatePoolAware
public event TypedEventHandler<TextBox, TextBoxBeforeTextChangingEventArgs> 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);
Expand Down

0 comments on commit e58e5bc

Please sign in to comment.