TextBox.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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 [email protected]
  24. //
  25. //
  26. // NOT COMPLETE
  27. using System;
  28. using System.ComponentModel;
  29. using System.ComponentModel.Design;
  30. using System.Drawing;
  31. namespace System.Windows.Forms {
  32. public class TextBox : TextBoxBase {
  33. #region Local Variables
  34. internal char password_char;
  35. #endregion // Local Variables
  36. #region Public Constructors
  37. public TextBox() {
  38. accepts_return = false;
  39. password_char = '\u25cf';
  40. scrollbars = RichTextBoxScrollBars.None;
  41. alignment = HorizontalAlignment.Left;
  42. this.LostFocus +=new EventHandler(TextBox_LostFocus);
  43. this.BackColor = ThemeEngine.Current.ColorWindow;
  44. this.ForeColor = ThemeEngine.Current.ColorWindowText;
  45. SetStyle (ControlStyles.StandardClick | ControlStyles.StandardDoubleClick, false);
  46. SetStyle (ControlStyles.FixedHeight, true);
  47. }
  48. #endregion // Public Constructors
  49. #region Private & Internal Methods
  50. private void TextBox_LostFocus(object sender, EventArgs e) {
  51. has_focus = false;
  52. //blah Console.WriteLine("TextBox.cs(56) Invalidate called in TextBox_LostFocus");
  53. Invalidate();
  54. }
  55. #endregion // Private & Internal Methods
  56. #region Public Instance Properties
  57. [DefaultValue(false)]
  58. public bool AcceptsReturn {
  59. get {
  60. return accepts_return;
  61. }
  62. set {
  63. if (value != accepts_return) {
  64. accepts_return = value;
  65. }
  66. }
  67. }
  68. [DefaultValue(CharacterCasing.Normal)]
  69. public CharacterCasing CharacterCasing {
  70. get {
  71. return character_casing;
  72. }
  73. set {
  74. if (value != character_casing) {
  75. character_casing = value;
  76. }
  77. }
  78. }
  79. [Localizable(true)]
  80. [DefaultValue('\0')]
  81. public char PasswordChar {
  82. get {
  83. return password_char;
  84. }
  85. set {
  86. if (value != password_char) {
  87. password_char = value;
  88. }
  89. }
  90. }
  91. [DefaultValue(ScrollBars.None)]
  92. [Localizable(true)]
  93. public ScrollBars ScrollBars {
  94. get {
  95. return (ScrollBars)scrollbars;
  96. }
  97. set {
  98. if (value != (ScrollBars)scrollbars) {
  99. scrollbars = (RichTextBoxScrollBars)value;
  100. base.CalculateScrollBars();
  101. }
  102. }
  103. }
  104. [Browsable(false)]
  105. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  106. public override int SelectionLength {
  107. get {
  108. return base.SelectionLength;
  109. }
  110. set {
  111. base.SelectionLength = value;
  112. }
  113. }
  114. public override string Text {
  115. get {
  116. return base.Text;
  117. }
  118. set {
  119. base.Text = value;
  120. }
  121. }
  122. [DefaultValue(HorizontalAlignment.Left)]
  123. [Localizable(true)]
  124. public HorizontalAlignment TextAlign {
  125. get {
  126. return alignment;
  127. }
  128. set {
  129. if (value != alignment) {
  130. alignment = value;
  131. // MS word-wraps if alignment isn't left
  132. if (multiline) {
  133. if (alignment != HorizontalAlignment.Left) {
  134. document.Wrap = true;
  135. } else {
  136. document.Wrap = word_wrap;
  137. }
  138. }
  139. for (int i = 1; i <= document.Lines; i++) {
  140. document.GetLine(i).Alignment = value;
  141. }
  142. document.RecalculateDocument(CreateGraphics());
  143. OnTextAlignChanged(EventArgs.Empty);
  144. }
  145. }
  146. }
  147. #endregion // Public Instance Properties
  148. #region Protected Instance Methods
  149. protected override CreateParams CreateParams {
  150. get {
  151. return base.CreateParams;
  152. }
  153. }
  154. protected override ImeMode DefaultImeMode {
  155. get {
  156. return base.DefaultImeMode;
  157. }
  158. }
  159. #endregion // Protected Instance Methods
  160. #region Protected Instance Methods
  161. protected override bool IsInputKey(Keys keyData) {
  162. return base.IsInputKey (keyData);
  163. }
  164. protected override void OnGotFocus(EventArgs e) {
  165. has_focus=true;
  166. //blah Console.WriteLine("TextBox.cs(190) Invalidate called in OnGotFocus");
  167. Invalidate();
  168. base.OnGotFocus (e);
  169. }
  170. protected override void OnHandleCreated(EventArgs e) {
  171. base.OnHandleCreated (e);
  172. }
  173. protected override void OnMouseUp(MouseEventArgs e) {
  174. base.OnMouseUp (e);
  175. }
  176. protected virtual void OnTextAlignChanged(EventArgs e) {
  177. if (TextAlignChanged != null) {
  178. TextAlignChanged(this, e);
  179. }
  180. }
  181. protected override void WndProc(ref Message m) {
  182. base.WndProc(ref m);
  183. }
  184. #endregion // Protected Instance Methods
  185. #region Events
  186. public event EventHandler TextAlignChanged;
  187. #endregion // Events
  188. }
  189. }