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:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
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.
20 // Copyright (c) 2004-2006 Novell, Inc. (http://www.novell.com)
23 // Peter Bartok pbartok@novell.com
30 using System.ComponentModel;
31 using System.ComponentModel.Design;
34 namespace System.Windows.Forms {
35 public class TextBox : TextBoxBase {
37 private ContextMenu menu;
38 private MenuItem undo;
40 private MenuItem copy;
41 private MenuItem paste;
42 private MenuItem delete;
43 private MenuItem select_all;
44 #endregion // Variables
46 #region Public Constructors
49 scrollbars = RichTextBoxScrollBars.None;
50 alignment = HorizontalAlignment.Left;
51 this.LostFocus +=new EventHandler(TextBox_LostFocus);
52 this.BackColor = ThemeEngine.Current.ColorWindow;
53 this.ForeColor = ThemeEngine.Current.ColorWindowText;
55 SetStyle (ControlStyles.StandardClick | ControlStyles.StandardDoubleClick, false);
56 SetStyle (ControlStyles.FixedHeight, true);
58 undo = new MenuItem(Locale.GetText("&Undo"));
59 cut = new MenuItem(Locale.GetText("Cu&t"));
60 copy = new MenuItem(Locale.GetText("&Copy"));
61 paste = new MenuItem(Locale.GetText("&Paste"));
62 delete = new MenuItem(Locale.GetText("&Delete"));
63 select_all = new MenuItem(Locale.GetText("Select &All"));
65 menu = new ContextMenu(new MenuItem[] { undo, new MenuItem("-"), cut, copy, paste, delete, new MenuItem("-"), select_all});
68 menu.Popup += new EventHandler(menu_Popup);
69 undo.Click += new EventHandler(undo_Click);
70 cut.Click += new EventHandler(cut_Click);
71 copy.Click += new EventHandler(copy_Click);
72 paste.Click += new EventHandler(paste_Click);
73 delete.Click += new EventHandler(delete_Click);
74 select_all.Click += new EventHandler(select_all_Click);
76 #endregion // Public Constructors
79 #region Private & Internal Methods
80 private void TextBox_LostFocus(object sender, EventArgs e) {
84 #endregion // Private & Internal Methods
86 #region Public Instance Properties
88 private bool use_system_password_char = false;
91 public bool UseSystemPasswordChar {
93 return use_system_password_char;
97 use_system_password_char = value;
102 [DefaultValue(false)]
103 public bool AcceptsReturn {
105 return accepts_return;
109 if (value != accepts_return) {
110 accepts_return = value;
115 [DefaultValue(CharacterCasing.Normal)]
116 public CharacterCasing CharacterCasing {
118 return character_casing;
122 if (value != character_casing) {
123 character_casing = value;
130 public char PasswordChar {
133 if (use_system_password_char) {
137 return password_char;
141 if (value != password_char) {
142 password_char = value;
144 document.PasswordChar = value.ToString();
146 document.PasswordChar = "";
152 [DefaultValue(ScrollBars.None)]
154 public ScrollBars ScrollBars {
156 return (ScrollBars)scrollbars;
160 if (value != (ScrollBars)scrollbars) {
161 scrollbars = (RichTextBoxScrollBars)value;
162 base.CalculateScrollBars();
168 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
169 public override int SelectionLength {
171 return base.SelectionLength;
174 base.SelectionLength = value;
179 public override string Text {
189 [DefaultValue(HorizontalAlignment.Left)]
191 public HorizontalAlignment TextAlign {
197 if (value != alignment) {
200 // MS word-wraps if alignment isn't left
202 if (alignment != HorizontalAlignment.Left) {
203 document.Wrap = true;
205 document.Wrap = word_wrap;
209 for (int i = 1; i <= document.Lines; i++) {
210 document.GetLine(i).Alignment = value;
212 document.RecalculateDocument(CreateGraphicsInternal());
213 OnTextAlignChanged(EventArgs.Empty);
217 #endregion // Public Instance Properties
219 #region Protected Instance Methods
220 protected override CreateParams CreateParams {
222 return base.CreateParams;
226 protected override ImeMode DefaultImeMode {
228 return base.DefaultImeMode;
231 #endregion // Protected Instance Methods
233 #region Protected Instance Methods
234 protected override bool IsInputKey(Keys keyData) {
235 return base.IsInputKey (keyData);
238 protected override void OnGotFocus(EventArgs e) {
244 protected override void OnHandleCreated(EventArgs e) {
245 base.OnHandleCreated (e);
248 protected override void OnMouseUp(MouseEventArgs e) {
252 protected virtual void OnTextAlignChanged(EventArgs e) {
253 if (TextAlignChanged != null) {
254 TextAlignChanged(this, e);
258 protected override void WndProc(ref Message m) {
261 #endregion // Protected Instance Methods
264 public event EventHandler TextAlignChanged;
267 #region Private Methods
268 private void menu_Popup(object sender, EventArgs e) {
269 if (SelectionLength == 0) {
271 copy.Enabled = false;
277 if (SelectionLength == TextLength) {
278 select_all.Enabled = false;
280 select_all.Enabled = true;
284 undo.Enabled = false;
290 private void undo_Click(object sender, EventArgs e) {
294 private void cut_Click(object sender, EventArgs e) {
298 private void copy_Click(object sender, EventArgs e) {
302 private void paste_Click(object sender, EventArgs e) {
306 private void delete_Click(object sender, EventArgs e) {
310 private void select_all_Click(object sender, EventArgs e) {
313 #endregion // Private Methods