7 public class TextInputEventArgs : EventArgs {
10 public TextInputEventArgs(string s) {
16 public class TextInput : DrawingArea, IKeyPress {
19 private string killring = null;
20 Pango.FontDescription font;
22 public delegate void SelectHandler(object o, TextInputEventArgs s);
23 public event SelectHandler Selected;
25 public TextInput() : this("") { }
27 public TextInput(string Value) {
29 cursor = Value.Length;
30 font = Pango.FontDescription.FromString("Courier 12");
31 SetSizeRequest(-1, 12);
32 ModifyBg(StateType.Normal, new Gdk.Color(0xFF, 0xFF, 0xFF));
35 protected virtual void draw (Cairo.Context gr, int width, int height) {
36 gr.SetSourceRGB(0,0,0);
38 gr.Rectangle(new Cairo.Rectangle(0, 0, width, height));
41 Pango.Layout layout = new Pango.Layout(this.PangoContext);
42 layout.Width = Pango.Units.FromPixels(width);
43 layout.Alignment = Pango.Alignment.Left;
44 layout.FontDescription = font;
45 layout.SetText(Value);
46 Pango.CairoHelper.ShowLayout(gr, layout);
49 int h = Pango.Units.ToPixels(layout.FontDescription.Size) + 1;
50 gr.Rectangle(cursor*8, 0, 7, h);
54 protected override bool OnExposeEvent (Gdk.EventExpose args) {
55 Gdk.Window win = args.Window;
56 Cairo.Context g = Gdk.CairoHelper.Create (args.Window);
59 win.GetGeometry(out x, out y, out w, out h, out d);
63 ((IDisposable) g.Target).Dispose();
64 ((IDisposable) g).Dispose();
68 [GLib.ConnectBefore ()]
69 public virtual void KeyPress(object o, KeyPressEventArgs args) {
70 if ((args.Event.State & ModifierType.ControlMask) != 0) {
71 switch(args.Event.Key) {
73 killring = Value.Substring(0, cursor);
74 Value = Value.Substring(cursor);
78 killring = Value.Substring(cursor);
79 Value = Value.Substring(0, cursor);
82 int ws = Value.LastIndexOfAny(" ".ToCharArray());
87 killring = Value.Substring(ws + 1);
88 Value = Value.Substring(0, ws);
90 cursor = Value.Length;
93 if (killring == null) return;
94 Value = Value.Insert(cursor, killring);
95 cursor += killring.Length;
99 switch(args.Event.Key) {
100 case Gdk.Key.BackSpace:
101 if (cursor == 0) return;
103 Value = Value.Remove(cursor, 1);
106 if (Selected != null) {
107 TextInputEventArgs t = new TextInputEventArgs(Value);
113 if (cursor > 0) cursor--;
116 if (cursor < Value.Length) cursor++;
119 if (Selected != null) {
120 TextInputEventArgs t = new TextInputEventArgs(null);
126 if (args.Event.KeyValue > 128) return;
127 Value = Value.Insert(cursor, new String((char)args.Event.KeyValue, 1));