**** Merged from MCS ****
[mono-project.git] / mcs / class / System.Windows.Forms / System.Windows.Forms / TextBox.cs
blob1268896e568a7d56c40a475143d1430d87fb3174
1 //
2 // System.Windows.Forms.TextBox
3 //
4 // Author:
5 // stubbed out by Jackson Harper (jackson@latitudegeo.com)
6 // Dennis Hayes (dennish@Raytek.com)
7 // Aleksey Ryabchuk (ryabchuk@yahoo.com)
8 //
9 // (C) 2002 Ximian, Inc
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.ComponentModel;
35 namespace System.Windows.Forms {
37 // <summary>
38 // Represents a Windows text box control.
39 // </summary>
41 public class TextBox : TextBoxBase {
43 HorizontalAlignment textAlign;
44 bool acceptsReturn;
45 CharacterCasing characterCasing;
46 char passwordChar;
47 ScrollBars scrollbars;
49 [MonoTODO]
50 public TextBox()
52 textAlign = HorizontalAlignment.Left;
53 acceptsReturn = true;
54 characterCasing = CharacterCasing.Normal;
55 passwordChar = (char)0;
56 scrollbars = ScrollBars.None;
59 public bool AcceptsReturn {
60 get { return acceptsReturn; }
61 set {
62 if ( acceptsReturn != value ) {
63 int oldStyle = acceptsReturn ? (int)EditControlStyles.ES_WANTRETURN : 0;
64 acceptsReturn = value;
65 int newStyle = acceptsReturn ? (int)EditControlStyles.ES_WANTRETURN : 0;
66 if ( IsHandleCreated )
67 Win32.UpdateWindowStyle ( Handle, oldStyle, newStyle );
72 public CharacterCasing CharacterCasing {
73 get { return characterCasing; }
74 set {
75 if ( !Enum.IsDefined ( typeof(CharacterCasing), value ) )
76 throw new InvalidEnumArgumentException( "CharacterCasing",
77 (int)value,
78 typeof(CharacterCasing));
80 if ( characterCasing != value ) {
81 int oldStyle = CaseStyle;
82 characterCasing = value;
83 if ( IsHandleCreated )
84 Win32.UpdateWindowStyle ( Handle, oldStyle, CaseStyle );
89 public char PasswordChar {
90 get { return passwordChar; }
91 set {
92 passwordChar = value;
93 if ( IsHandleCreated )
94 Win32.SendMessage ( Handle, (int) EditControlMessages.EM_SETPASSWORDCHAR, passwordChar, 0 );
98 public ScrollBars ScrollBars {
99 get { return scrollbars; }
100 set {
101 if ( !Enum.IsDefined ( typeof(ScrollBars), value ) )
102 throw new InvalidEnumArgumentException( "ScrollBars",
103 (int)value,
104 typeof(ScrollBars));
106 if ( scrollbars != value ) {
107 int oldStyle = ScrollBarStyle;
108 scrollbars = value;
109 if ( IsHandleCreated )
110 Win32.UpdateWindowStyle ( Handle, oldStyle, ScrollBarStyle );
115 public HorizontalAlignment TextAlign {
116 get { return textAlign; }
117 set {
118 if ( !Enum.IsDefined ( typeof(HorizontalAlignment), value ) )
119 throw new InvalidEnumArgumentException( "TextAlign",
120 (int)value,
121 typeof(HorizontalAlignment));
123 if ( textAlign != value ) {
124 textAlign = value;
126 OnTextAlignChanged ( EventArgs.Empty );
131 public event EventHandler TextAlignChanged;
133 [MonoTODO]
134 protected override CreateParams CreateParams {
135 get {
136 CreateParams createParams = base.CreateParams;
138 createParams.ClassName = "EDIT";
139 createParams.Style |= (int) ( WindowStyles.WS_CHILD ) | TextAlignStyle | ScrollBarStyle | CaseStyle;
140 if ( AcceptsReturn )
141 createParams.Style |= (int)EditControlStyles.ES_WANTRETURN;
143 return createParams;
147 [MonoTODO]
148 protected override ImeMode DefaultImeMode {
149 get { return ImeMode.Inherit; }
152 // --- Protected Members
154 protected override bool IsInputKey(Keys keyData)
156 //FIXME:
157 return base.IsInputKey(keyData);
159 [MonoTODO]
160 protected override void OnHandleCreated(EventArgs e)
162 //FIXME:
163 base.OnHandleCreated(e);
164 if ( PasswordChar != 0 )
165 Win32.SendMessage ( Handle, (int) EditControlMessages.EM_SETPASSWORDCHAR, PasswordChar, 0 );
167 [MonoTODO]
168 protected override void OnMouseUp(MouseEventArgs mevent)
170 //FIXME:
171 base.OnMouseUp(mevent);
174 [MonoTODO]
175 protected override void OnGotFocus(EventArgs e) {
176 //FIXME:
177 base.OnGotFocus(e);
180 protected virtual void OnTextAlignChanged(EventArgs e)
182 if ( TextAlignChanged != null )
183 TextAlignChanged ( this, EventArgs.Empty );
185 [MonoTODO]
186 protected override void WndProc(ref Message m)
188 //FIXME:
189 base.WndProc(ref m);
192 private int TextAlignStyle
194 get {
195 int style = 0;
196 switch ( TextAlign ) {
197 case HorizontalAlignment.Left:
198 style = (int) EditControlStyles.ES_LEFT;
199 break;
200 case HorizontalAlignment.Center:
201 style = (int) EditControlStyles.ES_CENTER;
202 break;
203 case HorizontalAlignment.Right:
204 style = (int) EditControlStyles.ES_RIGHT;
205 break;
207 return style;
211 private int ScrollBarStyle
213 get {
214 int style = 0;
215 switch ( this.ScrollBars ) {
216 case ScrollBars.Vertical:
217 style = (int) WindowStyles.WS_VSCROLL;
218 break;
219 case ScrollBars.Horizontal:
220 if ( !WordWrap )
221 style = (int) WindowStyles.WS_HSCROLL;
222 break;
223 case ScrollBars.Both:
224 style = (int) WindowStyles.WS_VSCROLL;
225 if ( !WordWrap )
226 style = (int) WindowStyles.WS_HSCROLL;
228 break;
230 return style;
234 private int CaseStyle
236 get {
237 int style = 0;
238 switch ( this.CharacterCasing ) {
239 case CharacterCasing.Lower:
240 style = (int) EditControlStyles.ES_LOWERCASE;
241 break;
242 case CharacterCasing.Upper:
243 style = (int) EditControlStyles.ES_UPPERCASE;
244 break;
246 return style;