2005-09-25 Marek Sieradzki <marek.sieradzki@gmail.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                 #endregion      // Public Constructors
51
52
53                 #region Private & Internal Methods
54                 private void TextBox_LostFocus(object sender, EventArgs e) {
55                         has_focus = false;
56 //blah Console.WriteLine("TextBox.cs(56) Invalidate called in TextBox_LostFocus");
57                         Invalidate();
58                 }
59                 #endregion      // Private & Internal Methods
60
61                 #region Public Instance Properties
62                 [DefaultValue(false)]
63                 public bool AcceptsReturn {
64                         get {
65                                 return accepts_return;
66                         }
67
68                         set {
69                                 if (value != accepts_return) {
70                                         accepts_return = value;
71                                 }       
72                         }
73                 }
74
75                 [DefaultValue(CharacterCasing.Normal)]
76                 public CharacterCasing CharacterCasing {
77                         get {
78                                 return character_casing;
79                         }
80
81                         set {
82                                 if (value != character_casing) {
83                                         character_casing = value;
84                                 }
85                         }
86                 }
87
88                 [Localizable(true)]
89                 [DefaultValue("")]
90                 public char PasswordChar {
91                         get {
92                                 return password_char;
93                         }
94
95                         set {
96                                 if (value != password_char) {
97                                         password_char = value;
98                                 }
99                         }
100                 }
101
102                 [DefaultValue(ScrollBars.None)]
103                 [Localizable(true)]
104                 public ScrollBars ScrollBars {
105                         get {
106                                 return (ScrollBars)scrollbars;
107                         }
108
109                         set {
110                                 if (value != (ScrollBars)scrollbars) {
111                                         scrollbars = (RichTextBoxScrollBars)value;
112                                         base.CalculateScrollBars();
113                                 }
114                         }
115                 }
116
117                 [Browsable(false)]
118                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
119                 public override int SelectionLength {
120                         get {
121                                 return base.SelectionLength;
122                         }
123                         set {
124                                 base.SelectionLength = value;
125                         }
126                 }
127
128
129                 public override string Text {
130                         get {
131                                 return base.Text;
132                         }
133
134                         set {
135                                 base.Text = value;
136                         }
137                 }
138
139                 [DefaultValue(HorizontalAlignment.Left)]
140                 [Localizable(true)]
141                 public HorizontalAlignment TextAlign {
142                         get {
143                                 return alignment;
144                         }
145
146                         set {
147                                 if (value != alignment) {
148                                         alignment = value;
149
150                                         // MS word-wraps if alignment isn't left
151                                         if (multiline) {
152                                                 if (alignment != HorizontalAlignment.Left) {
153                                                         document.Wrap = true;
154                                                 } else {
155                                                         document.Wrap = word_wrap;
156                                                 }
157                                         }
158
159                                         for (int i = 1; i <= document.Lines; i++) {
160                                                 document.GetLine(i).Alignment = value;
161                                         }
162                                         document.RecalculateDocument(CreateGraphics());
163                                         OnTextAlignChanged(EventArgs.Empty);
164                                 }
165                         }
166                 }
167                 #endregion      // Public Instance Properties
168
169                 #region Protected Instance Methods
170                 protected override CreateParams CreateParams {
171                         get {
172                                 return base.CreateParams;
173                         }
174                 }
175
176                 protected override ImeMode DefaultImeMode {
177                         get {
178                                 return base.DefaultImeMode;
179                         }
180                 }
181                 #endregion      // Protected Instance Methods
182
183                 #region Protected Instance Methods
184                 protected override bool IsInputKey(Keys keyData) {
185                         return base.IsInputKey (keyData);
186                 }
187
188                 protected override void OnGotFocus(EventArgs e) {
189                         has_focus=true;
190 //blah Console.WriteLine("TextBox.cs(190) Invalidate called in OnGotFocus");
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 }