TextBoxBase.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. //
  2. // System.Windows.Forms.TextBoxBase
  3. //
  4. // Author:
  5. // stubbed out by Jackson Harper ([email protected])
  6. // Dennis Hayes ([email protected])
  7. // Remco de Jong ([email protected])
  8. // Joel Basson ([email protected])
  9. // (C) 2002 Ximian, Inc
  10. //
  11. using System.Drawing;
  12. namespace System.Windows.Forms {
  13. // <summary>
  14. // This is only a template. Nothing is implemented yet.
  15. //
  16. // </summary>
  17. public class TextBoxBase : Control {
  18. private int maxlength = 0;
  19. private Gtk.TextTagTable tagtable;
  20. private Gtk.TextBuffer textbuffer = null;
  21. //
  22. // --- Public Properties
  23. //
  24. public TextBoxBase () {
  25. }
  26. protected Gtk.TextBuffer TextBuffer {
  27. get {
  28. if (textbuffer == null) {
  29. tagtable = new Gtk.TextTagTable ();
  30. textbuffer = new Gtk.TextBuffer (tagtable);
  31. // attach events
  32. textbuffer.ModifiedChanged += new EventHandler (modified_changed_cb);
  33. }
  34. return textbuffer;
  35. }
  36. }
  37. protected override void OnTextChanged(EventArgs e)
  38. {
  39. TextBuffer.SetText(Text);
  40. }
  41. public override string Text {
  42. get{
  43. return TextBuffer.Text;
  44. }
  45. set{
  46. TextBuffer.SetText(value);
  47. }
  48. }
  49. [MonoTODO]
  50. public bool AcceptsTab {
  51. get
  52. {
  53. throw new NotImplementedException ();
  54. }
  55. set
  56. {
  57. throw new NotImplementedException ();
  58. }
  59. }
  60. [MonoTODO]
  61. public virtual bool AutoSize {
  62. get
  63. {
  64. throw new NotImplementedException ();
  65. }
  66. set
  67. {
  68. throw new NotImplementedException ();
  69. }
  70. }
  71. /*
  72. [MonoTODO]
  73. public override Image BackgroundImage {
  74. get
  75. {
  76. throw new NotImplementedException ();
  77. }
  78. set
  79. {
  80. throw new NotImplementedException ();
  81. }
  82. }
  83. [MonoTODO]
  84. public BorderStyle BorderStyle {
  85. get
  86. {
  87. throw new NotImplementedException ();
  88. }
  89. set
  90. {
  91. throw new NotImplementedException ();
  92. }
  93. }
  94. */ [MonoTODO]
  95. public bool CanUndo {
  96. get
  97. {
  98. throw new NotImplementedException ();
  99. }
  100. }
  101. [MonoTODO]
  102. public bool HideSelection {
  103. get
  104. {
  105. throw new NotImplementedException ();
  106. }
  107. set
  108. {
  109. throw new NotImplementedException ();
  110. }
  111. }
  112. [MonoTODO]
  113. public string[] Lines {
  114. get
  115. {
  116. throw new NotImplementedException ();
  117. }
  118. set
  119. {
  120. Clear ();
  121. foreach (String s in value) {
  122. AppendText (s + "\n");
  123. }
  124. }
  125. }
  126. [MonoTODO]
  127. public virtual int MaxLength {
  128. get
  129. {
  130. return maxlength;
  131. }
  132. set
  133. {
  134. maxlength = value;
  135. }
  136. }
  137. public bool Modified {
  138. get
  139. {
  140. return TextBuffer.Modified;
  141. }
  142. set
  143. {
  144. if (TextBuffer.Modified != value) { // only call if it has really been changed since this will trigger an event, is this correct behavior?
  145. TextBuffer.Modified = value;
  146. }
  147. }
  148. }
  149. [MonoTODO]
  150. public virtual bool Multiline {
  151. get
  152. {
  153. throw new NotImplementedException ();
  154. }
  155. set
  156. {
  157. throw new NotImplementedException ();
  158. }
  159. }
  160. [MonoTODO]
  161. public int PreferredHeight {
  162. get
  163. {
  164. throw new NotImplementedException ();
  165. }
  166. }
  167. public virtual bool ReadOnly {
  168. // needs to be overwritten by child classes
  169. get { return false; }
  170. set {}
  171. }
  172. [MonoTODO]
  173. public virtual string SelectedText {
  174. get
  175. {
  176. String selection = "";
  177. Gtk.TextIter start = new Gtk.TextIter ();
  178. Gtk.TextIter end = new Gtk.TextIter ();
  179. if (TextBuffer.GetSelectionBounds(out start, out end))
  180. selection = TextBuffer.GetText(start, end, true);
  181. return selection;
  182. }
  183. set
  184. {
  185. // paste text over selection
  186. }
  187. }
  188. [MonoTODO]
  189. public virtual int SelectionLength {
  190. get
  191. {
  192. throw new NotImplementedException ();
  193. }
  194. set
  195. {
  196. throw new NotImplementedException ();
  197. }
  198. }
  199. [MonoTODO]
  200. public int SelectionStart {
  201. get
  202. {
  203. throw new NotImplementedException ();
  204. }
  205. set
  206. {
  207. throw new NotImplementedException ();
  208. }
  209. }
  210. [MonoTODO]
  211. public virtual int TextLength {
  212. get
  213. {
  214. return Text.Length;
  215. }
  216. }
  217. [MonoTODO]
  218. public virtual bool WordWrap {
  219. get
  220. {
  221. return false;
  222. }
  223. set
  224. {
  225. }
  226. }
  227. // --- Public Methods
  228. public void AppendText(string text)
  229. {
  230. Text += text;
  231. }
  232. public void Clear()
  233. {
  234. TextBuffer.SetText("");
  235. }
  236. [MonoTODO]
  237. public void ClearUndo()
  238. {
  239. throw new NotImplementedException ();
  240. }
  241. public void Copy()
  242. {
  243. TextBuffer.CopyClipboard (Gtk.Clipboard.Get (Gdk.Atom.Intern("GDK_NONE", false)));
  244. }
  245. public void Cut()
  246. {
  247. TextBuffer.CutClipboard (Gtk.Clipboard.Get (Gdk.Atom.Intern("GDK_NONE", false)), true);
  248. }
  249. public void Paste()
  250. {
  251. // Wait for my gtk-sharp patch
  252. // TextBuffer.PasteClipboard(Gtk.Clipboard.Get (Gdk.Atom.Intern("GDK_NONE", false)), true);
  253. }
  254. [MonoTODO]
  255. public void ScrollToCaret()
  256. {
  257. throw new NotImplementedException ();
  258. }
  259. public void Select(int start, int length)
  260. {
  261. Gtk.TextIter iter_start, iter_end;
  262. TextBuffer.GetIterAtOffset (out iter_start, start);
  263. TextBuffer.GetIterAtOffset (out iter_end, length);
  264. TextBuffer.MoveMark(TextBuffer.InsertMark , iter_end);
  265. TextBuffer.MoveMark (TextBuffer.SelectionBound, iter_start);
  266. }
  267. public void SelectAll()
  268. {
  269. Gtk.TextIter iter_start, iter_end;
  270. TextBuffer.GetBounds (out iter_start, out iter_end);
  271. TextBuffer.MoveMark(TextBuffer.InsertMark , iter_end);
  272. TextBuffer.MoveMark (TextBuffer.SelectionBound, iter_start);
  273. }
  274. public override string ToString()
  275. {
  276. // MS.NET returns "System.Windows.Forms.TextBox, Text: textBox1"
  277. // return "System.Windows.Forms.TextBox, Text: " + this.name;
  278. throw new NotImplementedException ();
  279. }
  280. [MonoTODO]
  281. public void Undo()
  282. {
  283. throw new NotImplementedException ();
  284. }
  285. // --- Internal Events (Gtk)
  286. internal protected void modified_changed_cb (object o, EventArgs args)
  287. {
  288. OnModifiedChanged (EventArgs.Empty);
  289. }
  290. // --- Public Events
  291. [MonoTODO]
  292. public event EventHandler AcceptsTabChanged;
  293. [MonoTODO]
  294. public event EventHandler AutoSizeChanged;
  295. [MonoTODO]
  296. public event EventHandler BorderStyleChanged;
  297. [MonoTODO]
  298. //public override event EventHandler Click;
  299. [MonoTODO]
  300. public event EventHandler HideSelectionChanged;
  301. public event EventHandler ModifiedChanged;
  302. [MonoTODO]
  303. public event EventHandler MultilineChanged;
  304. public event EventHandler ReadOnlyChanged;
  305. // --- Protected Properties
  306. /*
  307. [MonoTODO]
  308. protected override CreateParams CreateParams {
  309. get
  310. {
  311. throw new NotImplementedException ();
  312. }
  313. }
  314. [MonoTODO]
  315. protected override Size DefaultSize {
  316. get
  317. {
  318. throw new NotImplementedException ();
  319. }
  320. }
  321. // --- Protected Methods
  322. [MonoTODO]
  323. protected override void CreateHandle()
  324. {
  325. throw new NotImplementedException ();
  326. }
  327. */
  328. [MonoTODO]
  329. /* protected override bool IsInputKey(Keys keyData)
  330. {
  331. throw new NotImplementedException ();
  332. }
  333. */ [MonoTODO]
  334. protected virtual void OnAcceptsTabChanged(EventArgs e)
  335. {
  336. throw new NotImplementedException ();
  337. }
  338. [MonoTODO]
  339. protected virtual void OnAutoSizeChanged(EventArgs e)
  340. {
  341. throw new NotImplementedException ();
  342. }
  343. [MonoTODO]
  344. protected virtual void OnBorderStyleChanged(EventArgs e)
  345. {
  346. throw new NotImplementedException ();
  347. }
  348. /*
  349. [MonoTODO]
  350. protected override void OnFontChanged(EventArgs e)
  351. {
  352. throw new NotImplementedException ();
  353. }
  354. [MonoTODO]
  355. protected override void OnHandleCreated(EventArgs e)
  356. {
  357. throw new NotImplementedException ();
  358. }
  359. [MonoTODO]
  360. protected override void OnHandleDestroyed(EventArgs e)
  361. {
  362. throw new NotImplementedException ();
  363. }
  364. */
  365. [MonoTODO]
  366. protected virtual void OnHideSelectionChanged(EventArgs e)
  367. {
  368. throw new NotImplementedException ();
  369. }
  370. [MonoTODO]
  371. protected virtual void OnModifiedChanged(EventArgs e)
  372. {
  373. if (ModifiedChanged != null)
  374. ModifiedChanged (this, e);
  375. }
  376. [MonoTODO]
  377. protected virtual void OnMultilineChanged(EventArgs e)
  378. {
  379. throw new NotImplementedException ();
  380. }
  381. protected virtual void OnReadOnlyChanged(EventArgs e)
  382. {
  383. if (ReadOnlyChanged != null)
  384. ReadOnlyChanged (this, e);
  385. }
  386. /* [MonoTODO]
  387. protected override bool ProcessDialogKey(Keys keyData)
  388. {
  389. throw new NotImplementedException ();
  390. }
  391. [MonoTODO]
  392. protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
  393. {
  394. throw new NotImplementedException ();
  395. }
  396. [MonoTODO]
  397. protected override void WndProc(ref Message m)
  398. {
  399. throw new NotImplementedException ();
  400. }
  401. */ }
  402. }