TextBoxBase.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884
  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. #define Debug
  28. using System.Drawing;
  29. using System.Drawing.Text;
  30. using System.Text;
  31. namespace System.Windows.Forms {
  32. public abstract class TextBoxBase : Control {
  33. #region Local Variables
  34. internal HorizontalAlignment alignment;
  35. internal bool accepts_tab;
  36. internal bool accepts_return;
  37. internal bool auto_size;
  38. internal BorderStyle border_style;
  39. internal CharacterCasing character_casing;
  40. internal bool undo;
  41. internal bool hide_selection;
  42. internal int max_length;
  43. internal bool modified;
  44. internal bool multiline;
  45. internal bool read_only;
  46. internal bool word_wrap;
  47. internal Document document;
  48. internal LineTag caret_tag; // tag our cursor is in
  49. internal int caret_pos; // position on the line our cursor is in (can be 0 = beginning of line)
  50. internal int viewport_x; // left visible pixel
  51. internal int viewport_y; // top visible pixel
  52. internal HScrollBar hscroll;
  53. internal VScrollBar vscroll;
  54. internal ScrollBars scrollbars;
  55. internal bool grabbed;
  56. internal bool richtext;
  57. #if Debug
  58. internal static bool draw_lines = false;
  59. #endif
  60. #endregion // Local Variables
  61. #region Private Constructor
  62. // Constructor will go when complete, only for testing - pdb
  63. public TextBoxBase() {
  64. alignment = HorizontalAlignment.Left;
  65. accepts_return = false;
  66. accepts_tab = false;
  67. auto_size = true;
  68. border_style = BorderStyle.Fixed3D;
  69. character_casing = CharacterCasing.Normal;
  70. undo = false;
  71. hide_selection = true;
  72. max_length = 32767;
  73. modified = false;
  74. multiline = false;
  75. read_only = false;
  76. word_wrap = true;
  77. richtext = false;
  78. document = new Document(this);
  79. MouseDown += new MouseEventHandler(TextBoxBase_MouseDown);
  80. MouseUp += new MouseEventHandler(TextBoxBase_MouseUp);
  81. MouseMove += new MouseEventHandler(TextBoxBase_MouseMove);
  82. SizeChanged += new EventHandler(TextBoxBase_SizeChanged);
  83. FontChanged += new EventHandler(TextBoxBase_FontOrColorChanged);
  84. ForeColorChanged += new EventHandler(TextBoxBase_FontOrColorChanged);
  85. scrollbars = ScrollBars.None;
  86. hscroll = new HScrollBar();
  87. hscroll.ValueChanged +=new EventHandler(hscroll_ValueChanged);
  88. hscroll.Enabled = true;
  89. hscroll.Visible = false;
  90. vscroll = new VScrollBar();
  91. vscroll.Visible = false;
  92. this.Controls.Add(hscroll);
  93. this.Controls.Add(vscroll);
  94. //SetStyle(ControlStyles.ResizeRedraw, true);
  95. SetStyle(ControlStyles.AllPaintingInWmPaint, true);
  96. SetStyle(ControlStyles.UserPaint, true);
  97. }
  98. #endregion // Private Constructor
  99. #region Private and Internal Methods
  100. internal string CaseAdjust(string s) {
  101. if (character_casing == CharacterCasing.Normal) {
  102. return s;
  103. }
  104. if (character_casing == CharacterCasing.Lower) {
  105. return s.ToLower();
  106. } else {
  107. return s.ToUpper();
  108. }
  109. }
  110. #endregion // Private and Internal Methods
  111. #region Public Instance Properties
  112. public bool AcceptsTab {
  113. get {
  114. return accepts_tab;
  115. }
  116. set {
  117. if (value != accepts_tab) {
  118. accepts_tab = value;
  119. OnAcceptsTabChanged(EventArgs.Empty);
  120. }
  121. }
  122. }
  123. public virtual bool AutoSize {
  124. get {
  125. return auto_size;
  126. }
  127. set {
  128. if (value != auto_size) {
  129. auto_size = value;
  130. OnAutoSizeChanged(EventArgs.Empty);
  131. }
  132. }
  133. }
  134. public override System.Drawing.Color BackColor {
  135. get {
  136. return base.BackColor;
  137. }
  138. set {
  139. base.BackColor = value;
  140. }
  141. }
  142. public override System.Drawing.Image BackgroundImage {
  143. get {
  144. return base.BackgroundImage;
  145. }
  146. set {
  147. base.BackgroundImage = value;
  148. }
  149. }
  150. public BorderStyle BorderStyle {
  151. get {
  152. return border_style;
  153. }
  154. set {
  155. if (value != border_style) {
  156. border_style = value;
  157. OnBorderStyleChanged(EventArgs.Empty);
  158. }
  159. }
  160. }
  161. public bool CanUndo {
  162. get {
  163. return undo;
  164. }
  165. }
  166. public override System.Drawing.Color ForeColor {
  167. get {
  168. return base.ForeColor;
  169. }
  170. set {
  171. base.ForeColor = value;
  172. }
  173. }
  174. public bool HideSelection {
  175. get {
  176. return hide_selection;
  177. }
  178. set {
  179. if (value != hide_selection) {
  180. hide_selection = value;
  181. OnHideSelectionChanged(EventArgs.Empty);
  182. }
  183. if (hide_selection) {
  184. document.selection_visible = false;
  185. } else {
  186. document.selection_visible = true;
  187. }
  188. document.InvalidateSelectionArea();
  189. }
  190. }
  191. public string[] Lines {
  192. get {
  193. string[] lines;
  194. int i;
  195. int l;
  196. l = document.Lines;
  197. lines = new string[l];
  198. for (i = 0; i < l; i++) {
  199. lines[i] = document.GetLine(i).text.ToString();
  200. }
  201. return lines;
  202. }
  203. set {
  204. int i;
  205. int l;
  206. Brush brush;
  207. document.Empty();
  208. l = value.Length;
  209. brush = ThemeEngine.Current.ResPool.GetSolidBrush(this.BackColor);
  210. for (i = 0; i < l; i++) {
  211. document.Add(i+1, CaseAdjust(value[i]), alignment, font, brush);
  212. }
  213. document.RecalculateDocument(CreateGraphics());
  214. }
  215. }
  216. public virtual int MaxLength {
  217. get {
  218. return max_length;
  219. }
  220. set {
  221. if (value != max_length) {
  222. max_length = value;
  223. }
  224. }
  225. }
  226. public bool Modified {
  227. get {
  228. return modified;
  229. }
  230. set {
  231. if (value != modified) {
  232. modified = value;
  233. OnModifiedChanged(EventArgs.Empty);
  234. }
  235. }
  236. }
  237. public virtual bool Multiline {
  238. get {
  239. return multiline;
  240. }
  241. set {
  242. if (value != multiline) {
  243. multiline = value;
  244. OnMultilineChanged(EventArgs.Empty);
  245. }
  246. document.multiline = multiline;
  247. }
  248. }
  249. public int PreferredHeight {
  250. get {
  251. return this.Font.Height + 7; // FIXME - consider border style as well
  252. }
  253. }
  254. public bool ReadOnly {
  255. get {
  256. return read_only;
  257. }
  258. set {
  259. if (value != read_only) {
  260. read_only = value;
  261. OnReadOnlyChanged(EventArgs.Empty);
  262. }
  263. }
  264. }
  265. public virtual string SelectedText {
  266. get {
  267. return document.GetSelection();
  268. }
  269. set {
  270. document.ReplaceSelection(CaseAdjust(value));
  271. }
  272. }
  273. public virtual int SelectionLength {
  274. get {
  275. return document.SelectionLength();
  276. }
  277. set {
  278. // FIXME
  279. }
  280. }
  281. public bool WordWrap {
  282. get {
  283. return word_wrap;
  284. }
  285. set {
  286. if (value != word_wrap) {
  287. word_wrap = value;
  288. }
  289. }
  290. }
  291. #endregion // Public Instance Properties
  292. #region Protected Instance Properties
  293. protected override CreateParams CreateParams {
  294. get {
  295. return base.CreateParams;
  296. }
  297. }
  298. protected override System.Drawing.Size DefaultSize {
  299. get {
  300. return base.DefaultSize;
  301. }
  302. }
  303. #endregion // Protected Instance Properties
  304. #region Public Instance Methods
  305. public void AppendText(string text) {
  306. // FIXME
  307. throw new NotImplementedException();
  308. }
  309. public void Clear() {
  310. // FIXME
  311. throw new NotImplementedException();
  312. }
  313. public void ClearUndo() {
  314. // FIXME
  315. throw new NotImplementedException();
  316. }
  317. public void Copy() {
  318. // FIXME
  319. throw new NotImplementedException();
  320. }
  321. public void Cut() {
  322. // FIXME
  323. throw new NotImplementedException();
  324. }
  325. public void Paste() {
  326. // FIXME
  327. throw new NotImplementedException();
  328. }
  329. public void ScrollToCaret() {
  330. // FIXME
  331. throw new NotImplementedException();
  332. }
  333. public void Select(int start, int length) {
  334. // FIXME
  335. throw new NotImplementedException();
  336. }
  337. public void SelectAll() {
  338. Line last;
  339. last = document.GetLine(document.Lines);
  340. document.SetSelectionStart(document.GetLine(1), 0);
  341. document.SetSelectionEnd(last, last.text.Length);
  342. }
  343. public override string ToString() {
  344. StringBuilder sb;
  345. int i;
  346. int end;
  347. sb = new StringBuilder();
  348. end = document.Lines;
  349. for (i = 1; i < end; i++) {
  350. sb.Append(document.GetLine(i).text.ToString() + "\n");
  351. }
  352. return sb.ToString();
  353. }
  354. public void Undo() {
  355. return;
  356. }
  357. #endregion // Public Instance Methods
  358. #region Protected Instance Methods
  359. protected override void CreateHandle() {
  360. base.CreateHandle ();
  361. }
  362. protected override bool IsInputKey(Keys keyData) {
  363. switch (keyData) {
  364. case Keys.Enter: {
  365. if (multiline && (accepts_return || ((keyData & Keys.Control) != 0))) {
  366. return true;
  367. }
  368. return false;
  369. }
  370. case Keys.Tab: {
  371. if (accepts_tab) {
  372. return true;
  373. }
  374. return false;
  375. }
  376. }
  377. return false;
  378. }
  379. protected virtual void OnAcceptsTabChanged(EventArgs e) {
  380. if (AcceptsTabChanged != null) {
  381. AcceptsTabChanged(this, e);
  382. }
  383. }
  384. protected virtual void OnAutoSizeChanged(EventArgs e) {
  385. if (AutoSizeChanged != null) {
  386. AutoSizeChanged(this, e);
  387. }
  388. }
  389. protected virtual void OnBorderStyleChanged(EventArgs e) {
  390. if (BorderStyleChanged != null) {
  391. BorderStyleChanged(this, e);
  392. }
  393. }
  394. protected override void OnFontChanged(EventArgs e) {
  395. base.OnFontChanged (e);
  396. }
  397. protected override void OnHandleCreated(EventArgs e) {
  398. base.OnHandleCreated (e);
  399. }
  400. protected override void OnHandleDestroyed(EventArgs e) {
  401. base.OnHandleDestroyed (e);
  402. }
  403. protected virtual void OnHideSelectionChanged(EventArgs e) {
  404. if (HideSelectionChanged != null) {
  405. HideSelectionChanged(this, e);
  406. }
  407. }
  408. protected virtual void OnModifiedChanged(EventArgs e) {
  409. if (ModifiedChanged != null) {
  410. ModifiedChanged(this, e);
  411. }
  412. }
  413. protected virtual void OnMultilineChanged(EventArgs e) {
  414. if (MultilineChanged != null) {
  415. MultilineChanged(this, e);
  416. }
  417. }
  418. protected virtual void OnReadOnlyChanged(EventArgs e) {
  419. if (ReadOnlyChanged != null) {
  420. ReadOnlyChanged(this, e);
  421. }
  422. }
  423. protected override bool ProcessDialogKey(Keys keyData) {
  424. return base.ProcessDialogKey (keyData);
  425. }
  426. protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
  427. // Make sure we don't get sized bigger than we want to be
  428. if (!richtext) {
  429. if (!multiline) {
  430. if (height > PreferredHeight) {
  431. height = PreferredHeight;
  432. }
  433. }
  434. }
  435. base.SetBoundsCore (x, y, width, height, specified);
  436. }
  437. protected override void WndProc(ref Message m) {
  438. switch ((Msg)m.Msg) {
  439. case Msg.WM_PAINT: {
  440. PaintEventArgs paint_event;
  441. #if !__MonoCS__
  442. XplatUIWin32.Win32SetFocus(Handle);
  443. #endif
  444. paint_event = XplatUI.PaintEventStart(Handle);
  445. PaintControl(paint_event);
  446. XplatUI.PaintEventEnd(Handle);
  447. DefWndProc(ref m);
  448. return;
  449. }
  450. case Msg.WM_SETFOCUS: {
  451. // Set caret
  452. document.CaretHasFocus();
  453. Console.WriteLine("Creating caret");
  454. base.WndProc(ref m);
  455. return;
  456. }
  457. case Msg.WM_KILLFOCUS: {
  458. // Kill caret
  459. document.CaretLostFocus();
  460. Console.WriteLine("Destroying caret");
  461. base.WndProc(ref m);
  462. return;
  463. }
  464. case Msg.WM_KEYDOWN: {
  465. switch ((Keys)(m.WParam.ToInt32())) {
  466. case Keys.Left: {
  467. if ((Control.ModifierKeys & Keys.Control) != 0) {
  468. document.MoveCaret(CaretDirection.WordBack);
  469. } else {
  470. document.MoveCaret(CaretDirection.CharBack);
  471. }
  472. return;
  473. }
  474. case Keys.Right: {
  475. if ((Control.ModifierKeys & Keys.Control) != 0) {
  476. document.MoveCaret(CaretDirection.WordForward);
  477. } else {
  478. document.MoveCaret(CaretDirection.CharForward);
  479. }
  480. return;
  481. }
  482. case Keys.Up: {
  483. document.MoveCaret(CaretDirection.LineUp);
  484. return;
  485. }
  486. case Keys.Down: {
  487. document.DumpTree(document.Root, true);
  488. document.MoveCaret(CaretDirection.LineDown);
  489. return;
  490. }
  491. case Keys.Home: {
  492. if ((Control.ModifierKeys & Keys.Control) != 0) {
  493. document.MoveCaret(CaretDirection.CtrlHome);
  494. } else {
  495. document.MoveCaret(CaretDirection.Home);
  496. }
  497. return;
  498. }
  499. case Keys.End: {
  500. if ((Control.ModifierKeys & Keys.Control) != 0) {
  501. document.MoveCaret(CaretDirection.CtrlEnd);
  502. } else {
  503. document.MoveCaret(CaretDirection.End);
  504. }
  505. return;
  506. }
  507. case Keys.Enter: {
  508. if (multiline && (accepts_return || ((Control.ModifierKeys & Keys.Control) != 0))) {
  509. document.Split(document.CaretLine, document.CaretTag, document.CaretPosition);
  510. document.UpdateView(document.CaretLine, 2, 0);
  511. document.MoveCaret(CaretDirection.CharForward);
  512. }
  513. return;
  514. }
  515. case Keys.Tab: {
  516. if (accepts_tab) {
  517. document.InsertChar(document.CaretLine, document.CaretPosition, '\t');
  518. }
  519. return;
  520. }
  521. case Keys.Back: {
  522. // delete only deletes on the line, doesn't do the combine
  523. if (document.CaretPosition == 0) {
  524. if (document.CaretLine.LineNo > 1) {
  525. Line line;
  526. int new_caret_pos;
  527. line = document.GetLine(document.CaretLine.LineNo - 1);
  528. new_caret_pos = line.text.Length;
  529. document.Combine(line, document.CaretLine);
  530. document.UpdateView(line, 1, 0);
  531. document.PositionCaret(line, new_caret_pos);
  532. document.UpdateCaret();
  533. }
  534. } else {
  535. document.DeleteChar(document.CaretTag, document.CaretPosition, false);
  536. document.MoveCaret(CaretDirection.CharBack);
  537. }
  538. return;
  539. }
  540. case Keys.Delete: {
  541. // delete only deletes on the line, doesn't do the combine
  542. if (document.CaretPosition == document.CaretLine.text.Length) {
  543. if (document.CaretLine.LineNo < document.Lines) {
  544. Line line;
  545. line = document.GetLine(document.CaretLine.LineNo + 1);
  546. document.Combine(document.CaretLine, line);
  547. document.UpdateView(document.CaretLine, 2, 0);
  548. #if Debug
  549. Line check_first;
  550. Line check_second;
  551. check_first = document.GetLine(document.CaretLine.LineNo);
  552. check_second = document.GetLine(check_first.line_no + 1);
  553. Console.WriteLine("Post-UpdateView: Y of first line: {0}, second line: {1}", check_first.Y, check_second.Y);
  554. #endif
  555. // Caret doesn't move
  556. }
  557. } else {
  558. document.DeleteChar(document.CaretTag, document.CaretPosition, true);
  559. }
  560. return;
  561. }
  562. }
  563. return;
  564. }
  565. case Msg.WM_CHAR: {
  566. if (m.WParam.ToInt32() >= 32) { // FIXME, tabs should probably go through
  567. switch (character_casing) {
  568. case CharacterCasing.Normal: {
  569. document.InsertCharAtCaret((char)m.WParam, true);
  570. return;
  571. }
  572. case CharacterCasing.Lower: {
  573. document.InsertCharAtCaret(Char.ToLower((char)m.WParam), true);
  574. return;
  575. }
  576. case CharacterCasing.Upper: {
  577. document.InsertCharAtCaret(Char.ToUpper((char)m.WParam), true);
  578. return;
  579. }
  580. }
  581. }
  582. return;
  583. }
  584. default: {
  585. base.WndProc(ref m);
  586. return;
  587. }
  588. }
  589. }
  590. #endregion // Protected Instance Methods
  591. #region Events
  592. public event EventHandler AcceptsTabChanged;
  593. public event EventHandler AutoSizeChanged;
  594. public event EventHandler BorderStyleChanged;
  595. public event EventHandler Click;
  596. public event EventHandler HideSelectionChanged;
  597. public event EventHandler ModifiedChanged;
  598. public event EventHandler MultilineChanged;
  599. public event PaintEventHandler Paint;
  600. public event EventHandler ReadOnlyChanged;
  601. #endregion // Events
  602. #region Private Methods
  603. public Document Document {
  604. get {
  605. return document;
  606. }
  607. set {
  608. document = value;
  609. }
  610. }
  611. static int current;
  612. private void PaintControl(PaintEventArgs pevent) {
  613. // Fill background
  614. pevent.Graphics.FillRectangle(ThemeEngine.Current.ResPool.GetSolidBrush(BackColor), pevent.ClipRectangle);
  615. pevent.Graphics.TextRenderingHint=TextRenderingHint.AntiAlias;
  616. // Draw the viewable document
  617. document.Draw(pevent.Graphics, pevent.ClipRectangle);
  618. // Set the scrollbar
  619. switch (scrollbars) {
  620. case ScrollBars.Both: {
  621. break;
  622. }
  623. case ScrollBars.Vertical: {
  624. break;
  625. }
  626. case ScrollBars.Horizontal: {
  627. hscroll.Minimum = 0;
  628. hscroll.Maximum = document.Width - this.Width;
  629. break;
  630. }
  631. }
  632. #if Debug
  633. int start;
  634. int end;
  635. Line line;
  636. int line_no;
  637. LineTag tag;
  638. Pen p;
  639. p = new Pen(Color.Red, 1);
  640. // First, figure out from what line to what line we need to draw
  641. start = document.GetLineByPixel(pevent.ClipRectangle.Top - viewport_y, false).line_no;
  642. end = document.GetLineByPixel(pevent.ClipRectangle.Bottom - viewport_y, false).line_no;
  643. Console.WriteLine("Starting drawing on line '{0}'", document.GetLine(start));
  644. Console.WriteLine("Ending drawing on line '{0}'", document.GetLine(end));
  645. line_no = start;
  646. while (line_no <= end) {
  647. line = document.GetLine(line_no);
  648. if (draw_lines) {
  649. for (int i = 0; i < line.text.Length; i++) {
  650. pevent.Graphics.DrawLine(p, (int)line.widths[i] - document.ViewPortX, line.Y - document.ViewPortY, (int)line.widths[i] - document.ViewPortX, line.Y + line.height - document.ViewPortY);
  651. }
  652. }
  653. line_no++;
  654. }
  655. #endif
  656. }
  657. private void TextBoxBase_MouseDown(object sender, MouseEventArgs e) {
  658. LineTag tag;
  659. Line line;
  660. int pos;
  661. if (e.Button == MouseButtons.Left) {
  662. document.PositionCaret(e.X, e.Y);
  663. document.SetSelectionToCaret(true);
  664. this.grabbed = true;
  665. this.Capture = true;
  666. return;
  667. }
  668. #if Debug
  669. if (e.Button == MouseButtons.Right) {
  670. draw_lines = !draw_lines;
  671. this.Invalidate();
  672. return;
  673. }
  674. tag = document.FindTag(e.X, e.Y, out pos, false);
  675. Console.WriteLine("Click found tag {0}, character {1}", tag, pos);
  676. line = tag.line;
  677. switch(current) {
  678. case 4: LineTag.FormatText(tag.line, pos, (pos+10)<line.Text.Length ? 10 : line.Text.Length - pos+1, new Font("impact", 20, FontStyle.Bold, GraphicsUnit.Pixel), ThemeEngine.Current.ResPool.GetSolidBrush(Color.Red)); break;
  679. case 1: LineTag.FormatText(tag.line, pos, (pos+10)<line.Text.Length ? 10 : line.Text.Length - pos+1, new Font("arial unicode ms", 24, FontStyle.Italic, GraphicsUnit.Pixel), ThemeEngine.Current.ResPool.GetSolidBrush(Color.DarkGoldenrod)); break;
  680. case 2: LineTag.FormatText(tag.line, pos, (pos+10)<line.Text.Length ? 10 : line.Text.Length - pos+1, new Font("arial", 10, FontStyle.Regular, GraphicsUnit.Pixel), ThemeEngine.Current.ResPool.GetSolidBrush(Color.Aquamarine)); break;
  681. case 3: LineTag.FormatText(tag.line, pos, (pos+10)<line.Text.Length ? 10 : line.Text.Length - pos+1, new Font("times roman", 16, FontStyle.Underline, GraphicsUnit.Pixel), ThemeEngine.Current.ResPool.GetSolidBrush(Color.Turquoise)); break;
  682. case 0: LineTag.FormatText(tag.line, pos, (pos+10)<line.Text.Length ? 10 : line.Text.Length - pos+1, new Font("times roman", 64, FontStyle.Italic | FontStyle.Bold, GraphicsUnit.Pixel), ThemeEngine.Current.ResPool.GetSolidBrush(Color.LightSeaGreen)); break;
  683. case 5: LineTag.FormatText(tag.line, pos, (pos+10)<line.Text.Length ? 10 : line.Text.Length - pos+1, ((TextBoxBase)sender).Font, ThemeEngine.Current.ResPool.GetSolidBrush(ForeColor)); break;
  684. }
  685. current++;
  686. if (current==6) {
  687. current=0;
  688. }
  689. // Update/Recalculate what we see
  690. document.UpdateView(line, 0);
  691. // Make sure our caret is properly positioned and sized
  692. document.AlignCaret();
  693. #endif
  694. }
  695. private void TextBoxBase_MouseUp(object sender, MouseEventArgs e) {
  696. this.Capture = false;
  697. this.grabbed = false;
  698. if (e.Button == MouseButtons.Left) {
  699. document.PositionCaret(e.X + viewport_x, e.Y + viewport_y);
  700. document.SetSelectionToCaret(false);
  701. document.DisplayCaret();
  702. return;
  703. }
  704. }
  705. #endregion // Private Methods
  706. private void TextBoxBase_SizeChanged(object sender, EventArgs e) {
  707. // First, check which scrollbars we need
  708. hscroll.Bounds = new Rectangle (ClientRectangle.Left, ClientRectangle.Bottom - hscroll.Height, Width, hscroll.Height);
  709. }
  710. private void hscroll_ValueChanged(object sender, EventArgs e) {
  711. XplatUI.ScrollWindow(this.Handle, document.ViewPortX-this.hscroll.Value, 0);
  712. document.ViewPortX = this.hscroll.Value;
  713. document.UpdateCaret();
  714. Console.WriteLine("Dude scrolled");
  715. }
  716. private void TextBoxBase_MouseMove(object sender, MouseEventArgs e) {
  717. // FIXME - handle auto-scrolling if mouse is to the right/left of the window
  718. if (grabbed) {
  719. document.PositionCaret(e.X + viewport_x, e.Y + viewport_y);
  720. document.SetSelectionToCaret(false);
  721. document.DisplayCaret();
  722. }
  723. }
  724. private void TextBoxBase_FontOrColorChanged(object sender, EventArgs e) {
  725. if (!richtext) {
  726. Line line;
  727. // Font changes apply to the whole document
  728. for (int i = 1; i <= document.Lines; i++) {
  729. line = document.GetLine(i);
  730. LineTag.FormatText(line, 1, line.text.Length, font, ThemeEngine.Current.ResPool.GetSolidBrush(ForeColor));
  731. document.UpdateView(line, 0);
  732. }
  733. // Make sure the caret height is matching the new font height
  734. document.AlignCaret();
  735. }
  736. }
  737. }
  738. }