TextBox.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 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.Drawing;
  29. namespace System.Windows.Forms {
  30. public class TextBox : TextBoxBase {
  31. #region Local Variables
  32. internal char password_char;
  33. internal ScrollBars scrollbars;
  34. #endregion // Local Variables
  35. #region Public Constructors
  36. public TextBox() {
  37. accepts_return = false;
  38. password_char = '\u25cf';
  39. scrollbars = ScrollBars.None;
  40. alignment = HorizontalAlignment.Left;
  41. }
  42. #endregion // Public Constructors
  43. #region Public Instance Properties
  44. public bool AcceptsReturn {
  45. get {
  46. return accepts_return;
  47. }
  48. set {
  49. if (value != accepts_return) {
  50. accepts_return = value;
  51. }
  52. }
  53. }
  54. public CharacterCasing CharacterCasing {
  55. get {
  56. return character_casing;
  57. }
  58. set {
  59. if (value != character_casing) {
  60. character_casing = value;
  61. }
  62. }
  63. }
  64. public char PasswordChar {
  65. get {
  66. return password_char;
  67. }
  68. set {
  69. if (value != password_char) {
  70. password_char = value;
  71. }
  72. }
  73. }
  74. public ScrollBars ScrollBars {
  75. get {
  76. return scrollbars;
  77. }
  78. set {
  79. if (value != scrollbars) {
  80. scrollbars = value;
  81. }
  82. }
  83. }
  84. public override string Text {
  85. get {
  86. return base.Text;
  87. }
  88. set {
  89. Line line;
  90. if (multiline) {
  91. string[] lines;
  92. lines = value.Split(new char[] {'\n'});
  93. this.Lines = lines;
  94. line = document.GetLine(1);
  95. document.SetSelectionStart(line, 0);
  96. line = document.GetLine(document.Lines);
  97. document.SetSelectionEnd(line, line.text.Length);
  98. document.PositionCaret(line, line.text.Length);
  99. } else {
  100. document.Clear();
  101. document.Add(1, CaseAdjust(value), alignment, font, ThemeEngine.Current.ResPool.GetSolidBrush(ForeColor));
  102. document.RecalculateDocument(CreateGraphics());
  103. line = document.GetLine(1);
  104. document.SetSelectionStart(line, 0);
  105. document.SetSelectionEnd(line, value.Length);
  106. document.PositionCaret(line, value.Length);
  107. }
  108. base.Text = value;
  109. }
  110. }
  111. public HorizontalAlignment TextAlign {
  112. get {
  113. return alignment;
  114. }
  115. set {
  116. if (value != alignment) {
  117. Line line;
  118. alignment = value;
  119. for (int i = 1; i <= document.Lines; i++) {
  120. document.GetLine(i).Alignment = value;
  121. }
  122. document.RecalculateDocument(CreateGraphics());
  123. OnTextAlignChanged(EventArgs.Empty);
  124. }
  125. }
  126. }
  127. #endregion // Public Instance Properties
  128. #region Protected Instance Methods
  129. protected override CreateParams CreateParams {
  130. get {
  131. return base.CreateParams;
  132. }
  133. }
  134. protected override ImeMode DefaultImeMode {
  135. get {
  136. return base.DefaultImeMode;
  137. }
  138. }
  139. #endregion // Protected Instance Methods
  140. #region Protected Instance Methods
  141. protected override bool IsInputKey(Keys keyData) {
  142. return base.IsInputKey (keyData);
  143. }
  144. protected override void OnGotFocus(EventArgs e) {
  145. base.OnGotFocus (e);
  146. }
  147. protected override void OnHandleCreated(EventArgs e) {
  148. base.OnHandleCreated (e);
  149. }
  150. protected override void OnMouseUp(MouseEventArgs e) {
  151. base.OnMouseUp (e);
  152. }
  153. protected virtual void OnTextAlignChanged(EventArgs e) {
  154. if (TextAlignChanged != null) {
  155. TextAlignChanged(this, e);
  156. }
  157. }
  158. protected virtual void WndProc(ref Message m) {
  159. base.WndProc(ref m);
  160. }
  161. #endregion // Protected Instance Methods
  162. #region Events
  163. public event EventHandler TextAlignChanged;
  164. #endregion // Events
  165. }
  166. }