-
Notifications
You must be signed in to change notification settings - Fork 12
/
TextBox.cocoa.cs
171 lines (149 loc) · 4.08 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
using System;
using MonoMac.AppKit;
using System.Drawing;
using MonoMac.Foundation;
namespace System.Windows.Forms
{
[MonoMac.Foundation.Register("TextBox")]
public partial class TextBox : Control // : TextBoxMouseView, IControl
//NSTextField
{
internal TextBoxMouseView m_helper;
internal override NSView c_helper {
get {
return m_helper;
}
set {
m_helper = value as TextBoxMouseView;
}
}
public TextBox ()
{
m_helper = new TextBoxMouseView();
m_helper.Host = this;
m_helper.Selectable = true;
m_helper.Editable = true;
Multiline = true;
m_helper.viewDidMoveToSuperview += delegate(object sender, EventArgs e) {
ViewDidMoveToSuperview();
};
//this.BackgroundColor = NSColor.Clear;
}
public virtual string Text {
get { return m_helper.StringValue; }
set { m_helper.StringValue = value; }
}
public string[] Lines
{
get{return m_helper.StringValue.Split(new char[] { '\n' });}
set{m_helper.StringValue = "";
foreach(var val in value)
{ m_helper.StringValue+= 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;
}
}
public bool Multiline{get;set;}
#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
{
set
{
switch(value)
{
case HorizontalAlignment.Left:
m_helper.Alignment = (uint)NSTextAlignment.Left;
break;
case HorizontalAlignment.Center:
m_helper.Alignment = (uint)NSTextAlignment.Center;
break;
case HorizontalAlignment.Right:
m_helper.Alignment = (uint)NSTextAlignment.Right;
break;
default : m_helper.Alignment = (uint) 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.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.BaseWritingDirection = NSWritingDirection.Embedding; break;
case RightToLeft.No: m_helper.BaseWritingDirection = NSWritingDirection.LeftToRight; break ;
case RightToLeft.Yes: m_helper.BaseWritingDirection = NSWritingDirection.RightToLeft ; break;
}
}
}
}
}