diff options
author | Jérémie Laval <jeremie.laval@gmail.com> | 2013-10-17 21:53:08 +0400 |
---|---|---|
committer | Jérémie Laval <jeremie.laval@gmail.com> | 2013-10-17 21:53:08 +0400 |
commit | c0fb2787ba440f15c90e59b8c3b5bf2c9274b561 (patch) | |
tree | c7d87675d68c315ae4e8ef1b30a8a818f5de875c /Xwt.Mac | |
parent | 524c59d4f7aa07379230a95d9227215a90c26de6 (diff) |
[Xwt.Mac] Implement PasswordEntry widget
Diffstat (limited to 'Xwt.Mac')
-rw-r--r-- | Xwt.Mac/Xwt.Mac.csproj | 1 | ||||
-rw-r--r-- | Xwt.Mac/Xwt.Mac/MacEngine.cs | 1 | ||||
-rw-r--r-- | Xwt.Mac/Xwt.Mac/PasswordEntryBackend.cs | 94 |
3 files changed, 96 insertions, 0 deletions
diff --git a/Xwt.Mac/Xwt.Mac.csproj b/Xwt.Mac/Xwt.Mac.csproj index c7fa2149..331ad68f 100644 --- a/Xwt.Mac/Xwt.Mac.csproj +++ b/Xwt.Mac/Xwt.Mac.csproj @@ -124,6 +124,7 @@ <Compile Include="Xwt.Mac.CellViews\CheckBoxTableCell.cs" /> <Compile Include="Xwt.Mac\EmbedNativeWidgetBackend.cs" /> <Compile Include="Xwt.Mac\MacKeyboardHandler.cs" /> + <Compile Include="Xwt.Mac\PasswordEntryBackend.cs" /> </ItemGroup> <Import Project="..\BuildHelpers.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> diff --git a/Xwt.Mac/Xwt.Mac/MacEngine.cs b/Xwt.Mac/Xwt.Mac/MacEngine.cs index 89fca49c..588a1a2d 100644 --- a/Xwt.Mac/Xwt.Mac/MacEngine.cs +++ b/Xwt.Mac/Xwt.Mac/MacEngine.cs @@ -121,6 +121,7 @@ namespace Xwt.Mac RegisterBackend <Xwt.Backends.ISliderBackend, SliderBackend> (); RegisterBackend <Xwt.Backends.IEmbeddedWidgetBackend, EmbedNativeWidgetBackend> (); RegisterBackend <Xwt.Backends.KeyboardHandler, MacKeyboardHandler> (); + RegisterBackend <Xwt.Backends.IPasswordEntryBackend, PasswordEntryBackend> (); } public override void RunApplication () diff --git a/Xwt.Mac/Xwt.Mac/PasswordEntryBackend.cs b/Xwt.Mac/Xwt.Mac/PasswordEntryBackend.cs new file mode 100644 index 00000000..6cff98ce --- /dev/null +++ b/Xwt.Mac/Xwt.Mac/PasswordEntryBackend.cs @@ -0,0 +1,94 @@ +using System; +using Xwt.Backends; +using MonoMac.AppKit; + +namespace Xwt.Mac +{ + public class PasswordEntryBackend : ViewBackend<NSView, IPasswordEntryEventSink>, IPasswordEntryBackend + { + public PasswordEntryBackend () + { + } + + public override void Initialize () + { + base.Initialize (); + ViewObject = new CustomAlignedContainer (new CustomSecureTextField (EventSink, ApplicationContext)); + } + + protected override void OnSizeToFit () + { + Container.SizeToFit (); + } + + CustomAlignedContainer Container { + get { return (CustomAlignedContainer)base.Widget; } + } + + public new NSSecureTextField Widget { + get { return (NSSecureTextField)Container.Child; } + } + + protected override Size GetNaturalSize () + { + var s = base.GetNaturalSize (); + return new Size (EventSink.GetDefaultNaturalSize ().Width, s.Height); + } + + public string Password { + get { + return Widget.StringValue; + } + set { + Widget.StringValue = value ?? string.Empty; + } + } + + public System.Security.SecureString SecurePassword { + get { + return null; + } + } + + public string PlaceholderText { + get { + return ((NSTextFieldCell)Widget.Cell).PlaceholderString; + } + set { + ((NSTextFieldCell)Widget.Cell).PlaceholderString = value ?? string.Empty; + } + } + } + + class CustomSecureTextField : NSSecureTextField, IViewObject + { + IPasswordEntryEventSink eventSink; + ApplicationContext context; + + public CustomSecureTextField (IPasswordEntryEventSink eventSink, ApplicationContext context) + { + this.context = context; + this.eventSink = eventSink; + Activated += (sender, e) => context.InvokeUserCode (delegate { + eventSink.OnActivated (); + }); + } + + public NSView View { + get { + return this; + } + } + + public ViewBackend Backend { get; set; } + + public override void DidChange (MonoMac.Foundation.NSNotification notification) + { + base.DidChange (notification); + context.InvokeUserCode (delegate { + eventSink.OnChanged (); + }); + } + } +} + |