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 [MWFCategory("Behavior")]
104 public bool AcceptsReturn {
106 return accepts_return;
110 if (value != accepts_return) {
111 accepts_return = value;
116 [DefaultValue(CharacterCasing.Normal)]
117 [MWFCategory("Behavior")]
118 public CharacterCasing CharacterCasing {
120 return character_casing;
124 if (value != character_casing) {
125 character_casing = value;
132 [MWFCategory("Behavior")]
133 public char PasswordChar {
136 if (use_system_password_char) {
140 return password_char;
144 if (value != password_char) {
145 password_char = value;
147 document.PasswordChar = value.ToString();
149 document.PasswordChar = "";
155 [DefaultValue(ScrollBars.None)]
157 [MWFCategory("Appearance")]
158 public ScrollBars ScrollBars {
160 return (ScrollBars)scrollbars;
164 if (value != (ScrollBars)scrollbars) {
165 scrollbars = (RichTextBoxScrollBars)value;
166 base.CalculateScrollBars();
172 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
173 public override int SelectionLength {
175 return base.SelectionLength;
178 base.SelectionLength = value;
183 public override string Text {
193 [DefaultValue(HorizontalAlignment.Left)]
195 [MWFCategory("Appearance")]
196 public HorizontalAlignment TextAlign {
202 if (value != alignment) {
205 // MS word-wraps if alignment isn't left
207 if (alignment != HorizontalAlignment.Left) {
208 document.Wrap = true;
210 document.Wrap = word_wrap;
214 for (int i = 1; i <= document.Lines; i++) {
215 document.GetLine(i).Alignment = value;
217 document.RecalculateDocument(CreateGraphicsInternal());
218 OnTextAlignChanged(EventArgs.Empty);
222 #endregion // Public Instance Properties
224 #region Protected Instance Methods
225 protected override CreateParams CreateParams {
227 return base.CreateParams;
231 protected override ImeMode DefaultImeMode {
233 return base.DefaultImeMode;
236 #endregion // Protected Instance Methods
238 #region Protected Instance Methods
239 protected override bool IsInputKey(Keys keyData) {
240 return base.IsInputKey (keyData);
243 protected override void OnGotFocus(EventArgs e) {
249 protected override void OnHandleCreated(EventArgs e) {
250 base.OnHandleCreated (e);
253 protected override void OnMouseUp(MouseEventArgs e) {
257 protected virtual void OnTextAlignChanged(EventArgs e) {
258 if (TextAlignChanged != null) {
259 TextAlignChanged(this, e);
263 protected override void WndProc(ref Message m) {
266 #endregion // Protected Instance Methods
269 public event EventHandler TextAlignChanged;
272 #region Private Methods
273 private void menu_Popup(object sender, EventArgs e) {
274 if (SelectionLength == 0) {
276 copy.Enabled = false;
282 if (SelectionLength == TextLength) {
283 select_all.Enabled = false;
285 select_all.Enabled = true;
289 undo.Enabled = false;
295 private void undo_Click(object sender, EventArgs e) {
299 private void cut_Click(object sender, EventArgs e) {
303 private void copy_Click(object sender, EventArgs e) {
307 private void paste_Click(object sender, EventArgs e) {
311 private void delete_Click(object sender, EventArgs e) {
315 private void select_all_Click(object sender, EventArgs e) {
318 #endregion // Private Methods