TextBox.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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 (
  31. new Gtk.Adjustment (0, 0, 1, .1, .1, .1),
  32. new Gtk.Adjustment (0, 0, 1, .1, .1, .1));
  33. window.SetPolicy(Gtk.PolicyType.Never, Gtk.PolicyType.Never);
  34. window.AddWithViewport(TextView);
  35. return window;
  36. }
  37. // --- Public Properties
  38. public override bool ReadOnly {
  39. get
  40. {
  41. return !TextView.Editable;
  42. }
  43. set
  44. {
  45. if (value == TextView.Editable) { // only change if value is different, correct behaviour?
  46. TextView.Editable = !value;
  47. OnReadOnlyChanged(EventArgs.Empty);
  48. }
  49. }
  50. }
  51. [MonoTODO]
  52. public bool AcceptsReturn {
  53. get
  54. {
  55. throw new NotImplementedException ();
  56. }
  57. set
  58. {
  59. throw new NotImplementedException ();
  60. }
  61. }
  62. [MonoTODO]
  63. /* public CharacterCasing CharacterCasing {
  64. get
  65. {
  66. throw new NotImplementedException ();
  67. }
  68. set
  69. {
  70. throw new NotImplementedException ();
  71. }
  72. }
  73. */ [MonoTODO]
  74. public char PasswordChar {
  75. get
  76. {
  77. throw new NotImplementedException ();
  78. }
  79. set
  80. {
  81. throw new NotImplementedException ();
  82. }
  83. }
  84. public ScrollBars ScrollBars {
  85. get {
  86. return scrollbars;
  87. }
  88. set {
  89. scrollbars = value;
  90. Gtk.PolicyType vpolicy = Gtk.PolicyType.Never; // correct behaviour?
  91. Gtk.PolicyType hpolicy = Gtk.PolicyType.Never;
  92. if (scrollbars == ScrollBars.Both) {
  93. vpolicy = Gtk.PolicyType.Always;
  94. hpolicy = Gtk.PolicyType.Always;
  95. }
  96. else if (scrollbars == ScrollBars.Horizontal) {
  97. hpolicy = Gtk.PolicyType.Always;
  98. }
  99. else if (scrollbars == ScrollBars.Vertical) {
  100. vpolicy = Gtk.PolicyType.Always;
  101. }
  102. ((Gtk.ScrolledWindow) Widget).SetPolicy(hpolicy, vpolicy);
  103. }
  104. }
  105. public HorizontalAlignment TextAlign {
  106. get
  107. {
  108. return textalign;
  109. }
  110. set
  111. {
  112. Gtk.Justification justification = Gtk.Justification.Left;
  113. if (value == HorizontalAlignment.Center) {
  114. justification = Gtk.Justification.Center;
  115. }
  116. else if (value == HorizontalAlignment.Right) {
  117. justification = Gtk.Justification.Right;
  118. }
  119. TextView.Justification = justification;
  120. textalign = value;
  121. OnTextAlignChanged(EventArgs.Empty);
  122. }
  123. }
  124. public override bool WordWrap {
  125. get
  126. {
  127. return wordwrap;
  128. }
  129. set
  130. {
  131. Gtk.WrapMode wrapmode = Gtk.WrapMode.None;
  132. wordwrap = value;
  133. if (wordwrap)
  134. wrapmode = Gtk.WrapMode.Word;
  135. TextView.WrapMode = wrapmode;
  136. }
  137. }
  138. // --- Public Events
  139. public event EventHandler TextAlignChanged;
  140. // --- Protected Properties
  141. /* [MonoTODO]
  142. protected override CreateParams CreateParams {
  143. get
  144. {
  145. throw new NotImplementedException ();
  146. }
  147. }
  148. [MonoTODO]
  149. protected override ImeMode DefaultImeMode {
  150. get
  151. {
  152. throw new NotImplementedException ();
  153. }
  154. }
  155. */
  156. // --- Protected Members
  157. protected Gtk.TextView TextView {
  158. get {
  159. if (textview == null) {
  160. textview = new Gtk.TextView(TextBuffer);
  161. textview.Show();
  162. }
  163. return textview;
  164. }
  165. }
  166. /* protected override bool IsInputKey(Keys keyData)
  167. {
  168. throw new NotImplementedException ();
  169. }
  170. [MonoTODO]
  171. protected override void OnHandleCreated(EventArgs e)
  172. {
  173. throw new NotImplementedException ();
  174. }
  175. [MonoTODO]
  176. protected override void OnMouseUp(MouseEventArgs mevent)
  177. {
  178. throw new NotImplementedException ();
  179. }
  180. */
  181. protected virtual void OnTextAlignChanged(EventArgs e)
  182. {
  183. if (TextAlignChanged != null)
  184. TextAlignChanged (this, e);
  185. }
  186. /* [MonoTODO]
  187. protected override void WndProc(ref Message m)
  188. {
  189. throw new NotImplementedException ();
  190. }
  191. */ }
  192. }