Ooui-tws-port/Ooui/TextArea.cs

70 lines
1.9 KiB
C#
Raw Normal View History

2017-06-16 06:15:26 +00:00
using System;
namespace Ooui
{
2017-06-16 06:21:20 +00:00
public class TextArea : FormControl
2017-06-16 06:15:26 +00:00
{
public event TargetEventHandler Change {
2017-06-16 06:15:26 +00:00
add => AddEventListener ("change", value);
remove => RemoveEventListener ("change", value);
}
public event TargetEventHandler Input {
2017-06-19 05:28:14 +00:00
add => AddEventListener ("input", value);
remove => RemoveEventListener ("input", value);
}
2017-06-16 06:56:30 +00:00
string val = "";
public string Value {
get => val;
set => SetProperty (ref val, value ?? "", "value");
2017-06-16 06:15:26 +00:00
}
public int Rows {
2018-02-02 02:43:23 +00:00
get => GetAttribute ("rows", 2);
set => SetAttributeProperty ("rows", value);
2017-06-16 06:15:26 +00:00
}
public int Columns {
2018-02-02 02:43:23 +00:00
get => GetAttribute ("cols", 20);
set => SetAttributeProperty ("cols", value);
2017-06-16 06:15:26 +00:00
}
2018-02-02 04:18:16 +00:00
protected override bool HtmlNeedsFullEndElement => true;
2017-06-16 06:15:26 +00:00
public TextArea ()
: base ("textarea")
{
2017-06-24 20:34:47 +00:00
// Subscribe to the change event so we always get up-to-date values
Change += (s, e) => {};
2017-06-16 06:15:26 +00:00
}
2017-06-16 06:21:20 +00:00
public TextArea (string text)
: this ()
{
2017-11-26 20:18:33 +00:00
Value = text;
2017-06-16 06:21:20 +00:00
}
2017-06-24 20:34:47 +00:00
protected override bool TriggerEventFromMessage (Message message)
{
if (message.TargetId == Id && message.MessageType == MessageType.Event && (message.Key == "change" || message.Key == "input" || message.Key == "keyup")) {
var v = message.Value != null ? Convert.ToString (message.Value) : "";
if (val != v) {
val = v;
OnPropertyChanged ("Value");
}
2017-06-24 20:34:47 +00:00
}
return base.TriggerEventFromMessage (message);
}
2018-02-02 04:18:16 +00:00
#if !NO_XML
2018-02-02 04:18:16 +00:00
public override void WriteInnerHtml (System.Xml.XmlWriter w)
{
w.WriteString (val ?? "");
}
#endif
2017-06-16 06:15:26 +00:00
}
}