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