/
TextBox.cocoa.cs
210 lines (188 loc) · 5.63 KB
/
TextBox.cocoa.cs
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
203
204
205
206
207
208
209
//
// Copyright 2011 James Clancey
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.using System;
using AppKit;
using System.Drawing;
using Foundation;
namespace System.Windows.Forms
{
[Foundation.Register("TextBox")]
public partial class TextBox : TextBoxBase // : TextBoxMouseView, IControl
//NSTextField
{
/*
internal override void CreateHelper ()
{
m_helper = new TextBoxHelper();
m_helper.Host = this;
m_helper.TextView.Selectable = true;
m_helper.TextView.Editable = true;
Multiline = false;
m_helper.TextView.VerticallyResizable = false;
m_helper.TextView.HorizontallyResizable = true;
m_helper.TextView.AutoresizingMask = (NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable );
m_helper.TextView.TextContainer.ContainerSize = new SizeF(float.MaxValue,float.MaxValue);
m_helper.TextView.TextContainer.WidthTracksTextView = false;
//m_helper.viewDidMoveToSuperview += delegate(object sender, EventArgs e) {
// ViewDidMoveToSuperview();
//};
}
*/
internal override void UpdateBounds ()
{
m_helper.TextView.MinSize = bounds.Size;
base.UpdateBounds ();
}
public virtual string Text {
get { return m_helper.TextView.Value; }
set { m_helper.TextView.Value = value;
if(!Multiline)
m_helper.TextView.SetSingleLine();}
}
public string[] Lines
{
get{return m_helper.TextView.Value.Split(new char[] { '\n' });}
set{m_helper.TextView.Value = "";
foreach(var val in value)
{ m_helper.TextView.Value += val + "\n";}
}
}
private DockStyle dock = DockStyle.None;
public DockStyle Dock {
get{return dock;}
set{dock = value ;
//TODO resize;
}
}
public void ViewDidMoveToSuperview ()
{
if(Dock == DockStyle.Fill)
this.Size = Size.Round(m_helper.Superview.Bounds.Size);
setScrollBars();
}
private ScrollBars _scrollBars = ScrollBars.None;
public ScrollBars ScrollBars {
get{return _scrollBars;}
set
{
_scrollBars = value;
setScrollBars();
}
}
private void setScrollBars()
{
if(m_helper.EnclosingScrollView == null)
return;
switch(_scrollBars)
{
case ScrollBars.Both:
m_helper.EnclosingScrollView.HasVerticalScroller = true;
m_helper.EnclosingScrollView.HasHorizontalScroller = true;
return;
case ScrollBars.Horizontal:
m_helper.EnclosingScrollView.HasVerticalScroller = false;
m_helper.EnclosingScrollView.HasHorizontalScroller = true;
return;
case ScrollBars.Vertical:
m_helper.EnclosingScrollView.HasVerticalScroller = true;
m_helper.EnclosingScrollView.HasHorizontalScroller = false;
return;
case ScrollBars.None:
m_helper.EnclosingScrollView.HasVerticalScroller = false;
m_helper.EnclosingScrollView.HasHorizontalScroller = false;
return;
}
}
#region Events
#endregion
//TODO: consolidate
//TODO: make it work
public float Left{get;set;}
public float Right {get { if (m_helper.Superview == null) return -1;return (m_helper.Frame.X + this.Width) - m_helper.Superview.Frame.Width ;}}
public int Top{ get{ return (int)this.Location.Y;}
set { this.Location = new Point((int)this.Location.Y,value);}
}
public void Clear()
{
this.Text = string.Empty;
}
public HorizontalAlignment TextAlign
{
get {
switch(m_helper.TextView.Alignment)
{
case NSTextAlignment.Left:
return HorizontalAlignment.Left;
break;
case NSTextAlignment.Center:
return HorizontalAlignment.Center;
break;
case NSTextAlignment.Right:
return HorizontalAlignment.Right;
break;
default : return HorizontalAlignment.Left;
break;
}
}
set
{
switch(value)
{
case HorizontalAlignment.Left:
m_helper.TextView.Alignment = NSTextAlignment.Left;
break;
case HorizontalAlignment.Center:
m_helper.TextView.Alignment = NSTextAlignment.Center;
break;
case HorizontalAlignment.Right:
m_helper.TextView.Alignment = NSTextAlignment.Right;
break;
default : m_helper.TextView.Alignment = NSTextAlignment.Left;
break;
}
}
}
public Color BackColor {
get {return m_helper.BackgroundColor.ToColor();}
set { m_helper.BackgroundColor = value.ToNSColor();
}
}
public RightToLeft RightToLeft{
get{
switch(m_helper.TextView.BaseWritingDirection)
{
case NSWritingDirection.LeftToRight: return RightToLeft.No;
case NSWritingDirection.RightToLeft : return RightToLeft.Yes;
case NSWritingDirection.Natural : return RightToLeft.No;
default : return RightToLeft.No;
}
}
set {
switch(value)
{
case RightToLeft.Inherit : m_helper.TextView.BaseWritingDirection = NSWritingDirection.Embedding; break;
case RightToLeft.No: m_helper.TextView.BaseWritingDirection = NSWritingDirection.LeftToRight; break ;
case RightToLeft.Yes: m_helper.TextView.BaseWritingDirection = NSWritingDirection.RightToLeft ; break;
}
}
}
public void Paste (string text)
{
m_helper.SelectedText = text;
//document.ReplaceSelection (CaseAdjust (text), false);
//ScrollToCaret();
OnTextChanged(EventArgs.Empty);
}
}
}