Ooui-tws-port/Ooui/TextArea.cs

58 lines
1.6 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
{
2017-07-08 05:55:04 +00:00
public event TargetEventHandler Changed {
2017-06-16 06:15:26 +00:00
add => AddEventListener ("change", value);
remove => RemoveEventListener ("change", value);
}
2017-07-08 05:55:04 +00:00
public event TargetEventHandler Inputted {
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
}
int rows = 2;
public int Rows {
get => rows;
set => SetProperty (ref rows, value, "rows");
}
2017-06-16 06:17:21 +00:00
int cols = 20;
2017-06-16 06:15:26 +00:00
public int Columns {
get => cols;
set => SetProperty (ref cols, value, "cols");
}
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
Changed += (s, e) => {};
2017-06-16 06:15:26 +00:00
}
2017-06-16 06:21:20 +00:00
public TextArea (string text)
: this ()
{
Text = text;
}
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") {
2017-06-24 21:52:34 +00:00
// Don't need to notify here because the base implementation will fire the event
val = message.Value != null ? Convert.ToString (message.Value) : "";
2017-06-24 20:34:47 +00:00
}
return base.TriggerEventFromMessage (message);
}
2017-06-16 06:15:26 +00:00
}
}