TextBox.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. //
  2. // System.Windows.Forms.TextBox
  3. //
  4. // Author:
  5. // stubbed out by Jackson Harper ([email protected])
  6. // Dennis Hayes ([email protected])
  7. // Remco de Jong ([email protected])
  8. //
  9. // (C) 2002 Ximian, Inc
  10. //
  11. namespace System.Windows.Forms {
  12. // <summary>
  13. // This is only a template. Nothing is implemented yet.
  14. //
  15. // </summary>
  16. public class TextBox : TextBoxBase {
  17. private Gtk.TextView textview;
  18. private ScrollBars scrollbars;
  19. private HorizontalAlignment textalign;
  20. private bool wordwrap;
  21. //
  22. // --- Public Constructor
  23. //
  24. public TextBox() {
  25. scrollbars = ScrollBars.None;
  26. }
  27. internal override Gtk.Widget CreateWidget () {
  28. // needs to initialized with a textbuffer from TextBoxBase
  29. // we need default adjustments, but the scrolledwindow constructor does not take null as argument
  30. Gtk.ScrolledWindow window = new Gtk.ScrolledWindow (new Gtk.Adjustment (IntPtr.Zero), new Gtk.Adjustment (IntPtr.Zero));
  31. window.SetPolicy(Gtk.PolicyType.Never, Gtk.PolicyType.Never);
  32. window.AddWithViewport(TextView);
  33. return window;
  34. }
  35. // --- Public Properties
  36. public override bool ReadOnly {
  37. get
  38. {
  39. return !TextView.Editable;
  40. }
  41. set
  42. {
  43. if (value == TextView.Editable) { // only change if value is different, correct behaviour?
  44. TextView.Editable = !value;
  45. OnReadOnlyChanged(EventArgs.Empty);
  46. }
  47. }
  48. }
  49. [MonoTODO]
  50. public bool AcceptsReturn {
  51. get
  52. {
  53. throw new NotImplementedException ();
  54. }
  55. set
  56. {
  57. throw new NotImplementedException ();
  58. }
  59. }
  60. [MonoTODO]
  61. /* public CharacterCasing CharacterCasing {
  62. get
  63. {
  64. throw new NotImplementedException ();
  65. }
  66. set
  67. {
  68. throw new NotImplementedException ();
  69. }
  70. }
  71. */ [MonoTODO]
  72. public char PasswordChar {
  73. get
  74. {
  75. throw new NotImplementedException ();
  76. }
  77. set
  78. {
  79. throw new NotImplementedException ();
  80. }
  81. }
  82. public ScrollBars ScrollBars {
  83. get {
  84. return scrollbars;
  85. }
  86. set {
  87. scrollbars = value;
  88. Gtk.PolicyType vpolicy = Gtk.PolicyType.Never; // correct behaviour?
  89. Gtk.PolicyType hpolicy = Gtk.PolicyType.Never;
  90. if (scrollbars == ScrollBars.Both) {
  91. vpolicy = Gtk.PolicyType.Always;
  92. hpolicy = Gtk.PolicyType.Always;
  93. }
  94. else if (scrollbars == ScrollBars.Horizontal) {
  95. hpolicy = Gtk.PolicyType.Always;
  96. }
  97. else if (scrollbars == ScrollBars.Vertical) {
  98. vpolicy = Gtk.PolicyType.Always;
  99. }
  100. ((Gtk.ScrolledWindow) Widget).SetPolicy(hpolicy, vpolicy);
  101. }
  102. }
  103. public HorizontalAlignment TextAlign {
  104. get
  105. {
  106. return textalign;
  107. }
  108. set
  109. {
  110. Gtk.Justification justification = Gtk.Justification.Left;
  111. if (value == HorizontalAlignment.Center) {
  112. justification = Gtk.Justification.Center;
  113. }
  114. else if (value == HorizontalAlignment.Right) {
  115. justification = Gtk.Justification.Right;
  116. }
  117. TextView.Justification = justification;
  118. textalign = value;
  119. OnTextAlignChanged(EventArgs.Empty);
  120. }
  121. }
  122. public override bool WordWrap {
  123. get
  124. {
  125. return wordwrap;
  126. }
  127. set
  128. {
  129. Gtk.WrapMode wrapmode = Gtk.WrapMode.None;
  130. wordwrap = value;
  131. if (wordwrap)
  132. wrapmode = Gtk.WrapMode.Word;
  133. TextView.WrapMode = wrapmode;
  134. }
  135. }
  136. // --- Public Events
  137. public event EventHandler TextAlignChanged;
  138. // --- Protected Properties
  139. /* [MonoTODO]
  140. protected override CreateParams CreateParams {
  141. get
  142. {
  143. throw new NotImplementedException ();
  144. }
  145. }
  146. [MonoTODO]
  147. protected override ImeMode DefaultImeMode {
  148. get
  149. {
  150. throw new NotImplementedException ();
  151. }
  152. }
  153. */
  154. // --- Protected Members
  155. protected Gtk.TextView TextView {
  156. get {
  157. if (textview == null) {
  158. textview = new Gtk.TextView(TextBuffer);
  159. textview.Show();
  160. }
  161. return textview;
  162. }
  163. }
  164. /* protected override bool IsInputKey(Keys keyData)
  165. {
  166. throw new NotImplementedException ();
  167. }
  168. [MonoTODO]
  169. protected override void OnHandleCreated(EventArgs e)
  170. {
  171. throw new NotImplementedException ();
  172. }
  173. [MonoTODO]
  174. protected override void OnMouseUp(MouseEventArgs mevent)
  175. {
  176. throw new NotImplementedException ();
  177. }
  178. */
  179. protected virtual void OnTextAlignChanged(EventArgs e)
  180. {
  181. if (TextAlignChanged != null)
  182. TextAlignChanged (this, e);
  183. }
  184. /* [MonoTODO]
  185. protected override void WndProc(ref Message m)
  186. {
  187. throw new NotImplementedException ();
  188. }
  189. */ }
  190. }