blob: 6af75f1ede633139a49859ed6b0053bcf32fc598 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenTK.Input;
using Cairo;
using System.Diagnostics;
using System.Xml.Serialization;
using System.Globalization;
using System.ComponentModel;
using System.Runtime.InteropServices;
namespace Crow
{
public class TextBox : Label
{
#region CTOR
public TextBox(string _initialValue)
: base(_initialValue)
{
}
public TextBox()
{ }
#endregion
#region GraphicObject overrides
[XmlIgnore]public override bool HasFocus //trigger update when lost focus to errase text beam
{
get
{
return base.HasFocus;
}
set
{
base.HasFocus = value;
registerForGraphicUpdate();
}
}
[XmlAttributeAttribute()][DefaultValue(true)]
public override bool Focusable
{
get { return base.Focusable; }
set { base.Focusable = value; }
}
[XmlAttributeAttribute()][DefaultValue("White")]
public override Color Background {
get { return base.Background; }
set { base.Background = value; }
}
[XmlAttributeAttribute()][DefaultValue("Black")]
public override Color Foreground {
get { return base.Foreground; }
set { base.Foreground = value; }
}
protected override void onDraw (Context gr)
{
base.onDraw (gr);
FontExtents fe = gr.FontExtents;
}
#endregion
public event EventHandler<TextChangeEventArgs> TextChanged;
public virtual void OnTextChanged(Object sender, TextChangeEventArgs e)
{
TextChanged.Raise (this, e);
}
#region Keyboard handling
public override void onKeyDown (object sender, KeyboardKeyEventArgs e)
{
base.onKeyDown (sender, e);
Key key = e.Key;
switch (key)
{
case Key.Back:
if (!selectionIsEmpty)
{
// Text = Text.Remove(selectionStart, selectionEnd - selectionStart);
// selReleasePos = -1;
// currentCol = selBeginPos;
}
else
this.DeleteChar();
break;
case Key.Clear:
break;
case Key.Delete:
if (selectionIsEmpty)
CurrentColumn++;
this.DeleteChar ();
break;
case Key.Enter:
case Key.KeypadEnter:
OnTextChanged(this,new TextChangeEventArgs(Text));
break;
case Key.Escape:
Text = "";
CurrentColumn = 0;
SelRelease = -1;
break;
case Key.Home:
//TODO
if (e.Control)
CurrentLine = 0;
CurrentColumn = 0;
break;
case Key.End:
if (e.Control)
CurrentLine = int.MaxValue;
CurrentColumn = int.MaxValue;
break;
case Key.Insert:
break;
case Key.Left:
CurrentColumn--;
break;
case Key.Right:
CurrentColumn++;
break;
case Key.Up:
CurrentLine--;
break;
case Key.Down:
CurrentLine++;
break;
case Key.Menu:
break;
case Key.NumLock:
break;
case Key.PageDown:
break;
case Key.PageUp:
break;
case Key.RWin:
break;
case Key.Tab:
this.Insert("\t");
break;
case Key.KeypadDecimal:
this.Insert (".");
break;
case Key.Space:
this.Insert(" ");
break;
case Key.KeypadDivide:
case Key.Slash:
this.Insert("/");
break;
case Key.KeypadMultiply:
this.Insert("*");
break;
case Key.KeypadMinus:
case Key.Minus:
this.Insert("-");
break;
case Key.KeypadPlus:
case Key.Plus:
this.Insert("+");
break;
case Key.ShiftLeft:
case Key.ShiftRight:
case Key.AltLeft:
case Key.AltRight:
break;
case Key.Semicolon:
this.Insert(";");
break;
default:
if (!selectionIsEmpty)
{
// Text = Text.Remove(selectionStart, selectionEnd - selectionStart);
// currentCol = selBeginPos;
}
string k = "?";
if ((char)key >= 67 && (char)key <= 76)
k = ((int)key - 67).ToString();
else if ((char)key >= 109 && (char)key <= 118)
k = ((int)key - 109).ToString();
else if (e.Shift)
k = key.ToString();
else
k = key.ToString().ToLower();
this.Insert (k);
SelRelease = -1;
SelBegin = new Point(CurrentColumn, SelBegin.Y);
break;
}
registerForGraphicUpdate();
}
#endregion
}
}
|