This should fix #76928. This fix incorporates ideas from a patch
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / TextBox.cs
1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
8 // 
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 // 
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 //
20 // Copyright (c) 2004-2005 Novell, Inc. (http://www.novell.com)
21 //
22 // Authors:
23 //      Peter Bartok    pbartok@novell.com
24 //
25 //
26
27 // NOT COMPLETE
28
29 using System;
30 using System.ComponentModel;
31 using System.ComponentModel.Design;
32 using System.Drawing;
33
34 namespace System.Windows.Forms {
35         public class TextBox : TextBoxBase {
36                 #region Public Constructors
37                 public TextBox() {
38                         scrollbars = RichTextBoxScrollBars.None;
39                         alignment = HorizontalAlignment.Left;
40                         this.LostFocus +=new EventHandler(TextBox_LostFocus);
41                         this.BackColor = ThemeEngine.Current.ColorWindow;
42                         this.ForeColor = ThemeEngine.Current.ColorWindowText;
43
44                         SetStyle (ControlStyles.StandardClick | ControlStyles.StandardDoubleClick, false);
45                         SetStyle (ControlStyles.FixedHeight, true);
46                 }
47                 #endregion      // Public Constructors
48
49
50                 #region Private & Internal Methods
51                 private void TextBox_LostFocus(object sender, EventArgs e) {
52                         has_focus = false;
53                         Invalidate();
54                 }
55                 #endregion      // Private & Internal Methods
56
57                 #region Public Instance Properties
58                 [DefaultValue(false)]
59                 public bool AcceptsReturn {
60                         get {
61                                 return accepts_return;
62                         }
63
64                         set {
65                                 if (value != accepts_return) {
66                                         accepts_return = value;
67                                 }       
68                         }
69                 }
70
71                 [DefaultValue(CharacterCasing.Normal)]
72                 public CharacterCasing CharacterCasing {
73                         get {
74                                 return character_casing;
75                         }
76
77                         set {
78                                 if (value != character_casing) {
79                                         character_casing = value;
80                                 }
81                         }
82                 }
83
84                 [Localizable(true)]
85                 [DefaultValue('\0')]
86                 public char PasswordChar {
87                         get {
88                                 return password_char;
89                         }
90
91                         set {
92                                 if (value != password_char) {
93                                         password_char = value;
94                                         if (!multiline) {
95                                                 document.PasswordChar = value.ToString();
96                                         } else {
97                                                 document.PasswordChar = "";
98                                         }
99                                 }
100                         }
101                 }
102
103                 [DefaultValue(ScrollBars.None)]
104                 [Localizable(true)]
105                 public ScrollBars ScrollBars {
106                         get {
107                                 return (ScrollBars)scrollbars;
108                         }
109
110                         set {
111                                 if (value != (ScrollBars)scrollbars) {
112                                         scrollbars = (RichTextBoxScrollBars)value;
113                                         base.CalculateScrollBars();
114                                 }
115                         }
116                 }
117
118                 [Browsable(false)]
119                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
120                 public override int SelectionLength {
121                         get {
122                                 return base.SelectionLength;
123                         }
124                         set {
125                                 base.SelectionLength = value;
126                         }
127                 }
128
129
130                 public override string Text {
131                         get {
132                                 return base.Text;
133                         }
134
135                         set {
136                                 base.Text = value;
137                         }
138                 }
139
140                 [DefaultValue(HorizontalAlignment.Left)]
141                 [Localizable(true)]
142                 public HorizontalAlignment TextAlign {
143                         get {
144                                 return alignment;
145                         }
146
147                         set {
148                                 if (value != alignment) {
149                                         alignment = value;
150
151                                         // MS word-wraps if alignment isn't left
152                                         if (multiline) {
153                                                 if (alignment != HorizontalAlignment.Left) {
154                                                         document.Wrap = true;
155                                                 } else {
156                                                         document.Wrap = word_wrap;
157                                                 }
158                                         }
159
160                                         for (int i = 1; i <= document.Lines; i++) {
161                                                 document.GetLine(i).Alignment = value;
162                                         }
163                                         document.RecalculateDocument(CreateGraphics());
164                                         OnTextAlignChanged(EventArgs.Empty);
165                                 }
166                         }
167                 }
168                 #endregion      // Public Instance Properties
169
170                 #region Protected Instance Methods
171                 protected override CreateParams CreateParams {
172                         get {
173                                 return base.CreateParams;
174                         }
175                 }
176
177                 protected override ImeMode DefaultImeMode {
178                         get {
179                                 return base.DefaultImeMode;
180                         }
181                 }
182                 #endregion      // Protected Instance Methods
183
184                 #region Protected Instance Methods
185                 protected override bool IsInputKey(Keys keyData) {
186                         return base.IsInputKey (keyData);
187                 }
188
189                 protected override void OnGotFocus(EventArgs e) {
190                         has_focus=true;
191                         Invalidate();
192                         base.OnGotFocus (e);
193                 }
194
195                 protected override void OnHandleCreated(EventArgs e) {
196                         base.OnHandleCreated (e);
197                 }
198
199                 protected override void OnMouseUp(MouseEventArgs e) {
200                         base.OnMouseUp (e);
201                 }
202
203                 protected virtual void OnTextAlignChanged(EventArgs e) {
204                         if (TextAlignChanged != null) {
205                                 TextAlignChanged(this, e);
206                         }
207                 }
208
209                 protected override void WndProc(ref Message m) {
210                         base.WndProc(ref m);
211                 }
212                 #endregion      // Protected Instance Methods
213
214                 #region Events
215                 public event EventHandler TextAlignChanged;
216                 #endregion      // Events
217         }
218 }