2005-11-11 Peter Dennis Bartok <pbartok@novell.com>
[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 Local Variables
37                 internal char                   password_char;
38                 #endregion      // Local Variables
39
40                 #region Public Constructors
41                 public TextBox() {
42                         accepts_return = false;
43                         password_char = '\u25cf';
44                         scrollbars = RichTextBoxScrollBars.None;
45                         alignment = HorizontalAlignment.Left;
46                         this.LostFocus +=new EventHandler(TextBox_LostFocus);
47                         this.BackColor = ThemeEngine.Current.ColorWindow;
48                         this.ForeColor = ThemeEngine.Current.ColorWindowText;
49
50                         SetStyle (ControlStyles.StandardClick | ControlStyles.StandardDoubleClick, false);
51                         SetStyle (ControlStyles.FixedHeight, true);
52                 }
53                 #endregion      // Public Constructors
54
55
56                 #region Private & Internal Methods
57                 private void TextBox_LostFocus(object sender, EventArgs e) {
58                         has_focus = false;
59                         Invalidate();
60                 }
61                 #endregion      // Private & Internal Methods
62
63                 #region Public Instance Properties
64                 [DefaultValue(false)]
65                 public bool AcceptsReturn {
66                         get {
67                                 return accepts_return;
68                         }
69
70                         set {
71                                 if (value != accepts_return) {
72                                         accepts_return = value;
73                                 }       
74                         }
75                 }
76
77                 [DefaultValue(CharacterCasing.Normal)]
78                 public CharacterCasing CharacterCasing {
79                         get {
80                                 return character_casing;
81                         }
82
83                         set {
84                                 if (value != character_casing) {
85                                         character_casing = value;
86                                 }
87                         }
88                 }
89
90                 [Localizable(true)]
91                 [DefaultValue('\0')]
92                 public char PasswordChar {
93                         get {
94                                 return password_char;
95                         }
96
97                         set {
98                                 if (value != password_char) {
99                                         password_char = value;
100                                 }
101                         }
102                 }
103
104                 [DefaultValue(ScrollBars.None)]
105                 [Localizable(true)]
106                 public ScrollBars ScrollBars {
107                         get {
108                                 return (ScrollBars)scrollbars;
109                         }
110
111                         set {
112                                 if (value != (ScrollBars)scrollbars) {
113                                         scrollbars = (RichTextBoxScrollBars)value;
114                                         base.CalculateScrollBars();
115                                 }
116                         }
117                 }
118
119                 [Browsable(false)]
120                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
121                 public override int SelectionLength {
122                         get {
123                                 return base.SelectionLength;
124                         }
125                         set {
126                                 base.SelectionLength = value;
127                         }
128                 }
129
130
131                 public override string Text {
132                         get {
133                                 return base.Text;
134                         }
135
136                         set {
137                                 base.Text = value;
138                         }
139                 }
140
141                 [DefaultValue(HorizontalAlignment.Left)]
142                 [Localizable(true)]
143                 public HorizontalAlignment TextAlign {
144                         get {
145                                 return alignment;
146                         }
147
148                         set {
149                                 if (value != alignment) {
150                                         alignment = value;
151
152                                         // MS word-wraps if alignment isn't left
153                                         if (multiline) {
154                                                 if (alignment != HorizontalAlignment.Left) {
155                                                         document.Wrap = true;
156                                                 } else {
157                                                         document.Wrap = word_wrap;
158                                                 }
159                                         }
160
161                                         for (int i = 1; i <= document.Lines; i++) {
162                                                 document.GetLine(i).Alignment = value;
163                                         }
164                                         document.RecalculateDocument(CreateGraphics());
165                                         OnTextAlignChanged(EventArgs.Empty);
166                                 }
167                         }
168                 }
169                 #endregion      // Public Instance Properties
170
171                 #region Protected Instance Methods
172                 protected override CreateParams CreateParams {
173                         get {
174                                 return base.CreateParams;
175                         }
176                 }
177
178                 protected override ImeMode DefaultImeMode {
179                         get {
180                                 return base.DefaultImeMode;
181                         }
182                 }
183                 #endregion      // Protected Instance Methods
184
185                 #region Protected Instance Methods
186                 protected override bool IsInputKey(Keys keyData) {
187                         return base.IsInputKey (keyData);
188                 }
189
190                 protected override void OnGotFocus(EventArgs e) {
191                         has_focus=true;
192                         Invalidate();
193                         base.OnGotFocus (e);
194                 }
195
196                 protected override void OnHandleCreated(EventArgs e) {
197                         base.OnHandleCreated (e);
198                 }
199
200                 protected override void OnMouseUp(MouseEventArgs e) {
201                         base.OnMouseUp (e);
202                 }
203
204                 protected virtual void OnTextAlignChanged(EventArgs e) {
205                         if (TextAlignChanged != null) {
206                                 TextAlignChanged(this, e);
207                         }
208                 }
209
210                 protected override void WndProc(ref Message m) {
211                         base.WndProc(ref m);
212                 }
213                 #endregion      // Protected Instance Methods
214
215                 #region Events
216                 public event EventHandler TextAlignChanged;
217                 #endregion      // Events
218         }
219 }