Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/xwt.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Hutchinson <m.j.hutchinson@gmail.com>2013-09-18 23:45:23 +0400
committerMichael Hutchinson <m.j.hutchinson@gmail.com>2013-09-18 23:46:08 +0400
commit4d39e5ac90b92bf6f95237b3c913aa8adf5742f9 (patch)
tree8ad7c3bdcef23946e232637394e3d260a3887085 /Xwt.Gtk/Xwt.GtkBackend
parentdbfd9a64087f60a3536b9bc3ebb7a66af1eab8b6 (diff)
Add PasswordEntry.{PlaceholderText,SecurePassword}
Diffstat (limited to 'Xwt.Gtk/Xwt.GtkBackend')
-rw-r--r--Xwt.Gtk/Xwt.GtkBackend/PasswordEntryBackend.cs68
1 files changed, 60 insertions, 8 deletions
diff --git a/Xwt.Gtk/Xwt.GtkBackend/PasswordEntryBackend.cs b/Xwt.Gtk/Xwt.GtkBackend/PasswordEntryBackend.cs
index 4809f7b2..38811067 100644
--- a/Xwt.Gtk/Xwt.GtkBackend/PasswordEntryBackend.cs
+++ b/Xwt.Gtk/Xwt.GtkBackend/PasswordEntryBackend.cs
@@ -1,10 +1,13 @@
using Xwt.Backends;
using System;
+using Xwt.Drawing;
namespace Xwt.GtkBackend
{
public class PasswordEntryBackend : WidgetBackend, IPasswordEntryBackend
{
+ string placeHolderText;
+
public override void Initialize ()
{
Widget = new Gtk.Entry ();
@@ -22,20 +25,57 @@ namespace Xwt.GtkBackend
}
public string Password {
+ get { return Widget.Text; }
+ set { Widget.Text = value ?? ""; } // null value causes GTK error
+ }
+
+ public System.Security.SecureString SecurePassword {
+ get {
+ var text = Widget.Text;
+ unsafe {
+ fixed (char *ptr = text) {
+ return new System.Security.SecureString (ptr, text.Length);
+ }
+ }
+ }
+ }
+
+ public string PlaceholderText {
+ get { return placeHolderText; }
+ set {
+ if (placeHolderText != value) {
+ if (placeHolderText == null)
+ Widget.ExposeEvent += HandleWidgetExposeEvent;
+ else if (value == null)
+ Widget.ExposeEvent -= HandleWidgetExposeEvent;
+ }
+ placeHolderText = value;
+ }
+ }
+
+ public override Color BackgroundColor {
get {
- return Widget.Text;
+ return base.BackgroundColor;
}
set {
- Widget.Text = value;
+ base.BackgroundColor = value;
+ Widget.ModifyBase (Gtk.StateType.Normal, value.ToGdkColor ());
}
}
+ Pango.Layout layout;
+
+ void HandleWidgetExposeEvent (object o, Gtk.ExposeEventArgs args)
+ {
+ TextEntryBackend.RenderPlaceholderText (Widget, args, placeHolderText, ref layout);
+ }
+
public override void EnableEvent (object eventId)
{
base.EnableEvent (eventId);
- if (eventId is TextEntryEvent) {
- switch ((TextEntryEvent)eventId) {
- case TextEntryEvent.Changed: Widget.Changed += HandleChanged; break;
+ if (eventId is PasswordEntryEvent) {
+ switch ((PasswordEntryEvent)eventId) {
+ case PasswordEntryEvent.Changed: Widget.Changed += HandleChanged; break;
}
}
}
@@ -43,9 +83,9 @@ namespace Xwt.GtkBackend
public override void DisableEvent (object eventId)
{
base.DisableEvent (eventId);
- if (eventId is TextEntryEvent) {
- switch ((TextEntryEvent)eventId) {
- case TextEntryEvent.Changed: Widget.Changed -= HandleChanged; break;
+ if (eventId is PasswordEntryEvent) {
+ switch ((PasswordEntryEvent)eventId) {
+ case PasswordEntryEvent.Changed: Widget.Changed -= HandleChanged; break;
}
}
}
@@ -56,5 +96,17 @@ namespace Xwt.GtkBackend
EventSink.OnChanged ();
});
}
+
+ protected override void Dispose (bool disposing)
+ {
+ if (disposing) {
+ var l = layout;
+ if (l != null) {
+ l.Dispose ();
+ layout = null;
+ }
+ }
+ base.Dispose (disposing);
+ }
}
}