2005-02-17 Peter 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 = ScrollBars.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 \r
53                 #region Private & Internal Methods
54                 private void TextBox_LostFocus(object sender, EventArgs e) {\r
55                         has_focus = false;\r
56                         Invalidate();\r
57                 }\r
58                 #endregion      // Private & Internal Methods
59
60                 #region Public Instance Properties
61                 [DefaultValue(false)]
62                 public bool AcceptsReturn {
63                         get {
64                                 return accepts_return;
65                         }
66
67                         set {
68                                 if (value != accepts_return) {
69                                         accepts_return = value;
70                                 }       
71                         }
72                 }
73
74                 [DefaultValue(CharacterCasing.Normal)]
75                 public CharacterCasing CharacterCasing {
76                         get {
77                                 return character_casing;
78                         }
79
80                         set {
81                                 if (value != character_casing) {
82                                         character_casing = value;
83                                 }
84                         }
85                 }
86
87                 [Localizable(true)]
88                 [DefaultValue("")]
89                 public char PasswordChar {
90                         get {
91                                 return password_char;
92                         }
93
94                         set {
95                                 if (value != password_char) {
96                                         password_char = value;
97                                 }
98                         }
99                 }
100
101                 [DefaultValue(ScrollBars.None)]
102                 [Localizable(true)]
103                 public ScrollBars ScrollBars {
104                         get {
105                                 return scrollbars;
106                         }
107
108                         set {
109                                 if (value != scrollbars) {
110                                         scrollbars = value;
111                                 }
112                         }
113                 }
114
115                 [Browsable(false)]
116                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
117                 public override int SelectionLength {\r
118                         get {\r
119                                 return base.SelectionLength;\r
120                         }\r
121                         set {\r
122                                 base.SelectionLength = value;\r
123                         }\r
124                 }\r
125
126
127                 public override string Text {
128                         get {
129                                 return base.Text;
130                         }
131
132                         set {
133                                 base.Text = value;
134                         }
135                 }
136
137                 [DefaultValue(HorizontalAlignment.Left)]
138                 [Localizable(true)]
139                 public HorizontalAlignment TextAlign {
140                         get {
141                                 return alignment;
142                         }
143
144                         set {
145                                 if (value != alignment) {
146                                         alignment = value;
147                                         for (int i = 1; i <= document.Lines; i++) {
148                                                 document.GetLine(i).Alignment = value;
149                                         }
150                                         document.RecalculateDocument(CreateGraphics());
151                                         OnTextAlignChanged(EventArgs.Empty);
152                                 }
153                         }
154                 }
155                 #endregion      // Public Instance Properties
156
157                 #region Protected Instance Methods
158                 protected override CreateParams CreateParams {
159                         get {
160                                 return base.CreateParams;
161                         }
162                 }
163
164                 protected override ImeMode DefaultImeMode {
165                         get {
166                                 return base.DefaultImeMode;
167                         }
168                 }
169                 #endregion      // Protected Instance Methods
170
171                 #region Protected Instance Methods
172                 protected override bool IsInputKey(Keys keyData) {
173                         return base.IsInputKey (keyData);
174                 }
175
176                 protected override void OnGotFocus(EventArgs e) {
177                         has_focus=true;
178                         Invalidate();
179                         base.OnGotFocus (e);
180                 }
181
182                 protected override void OnHandleCreated(EventArgs e) {
183                         base.OnHandleCreated (e);
184                 }
185
186                 protected override void OnMouseUp(MouseEventArgs e) {
187                         base.OnMouseUp (e);
188                 }
189
190                 protected virtual void OnTextAlignChanged(EventArgs e) {
191                         if (TextAlignChanged != null) {
192                                 TextAlignChanged(this, e);
193                         }
194                 }
195
196                 protected override void WndProc(ref Message m) {
197                         base.WndProc(ref m);
198                 }
199                 #endregion      // Protected Instance Methods
200
201                 #region Events
202                 public event EventHandler TextAlignChanged;
203                 #endregion      // Events\r
204         }
205 }