comparison dwtx/ui/internal/forms/widgets/TextSegment.d @ 104:04b47443bb01

Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections. These new wrappers now use the tango.util.containers instead of the tango.util.collections.
author Frank Benoit <benoit@tionex.de>
date Thu, 07 Aug 2008 15:01:33 +0200
parents 11e8159caf7a
children
comparison
equal deleted inserted replaced
103:2d6540440fe6 104:04b47443bb01
27 import dwt.graphics.Point; 27 import dwt.graphics.Point;
28 import dwt.graphics.Rectangle; 28 import dwt.graphics.Rectangle;
29 29
30 import dwt.dwthelper.utils; 30 import dwt.dwthelper.utils;
31 import dwtx.dwtxhelper.mangoicu.UBreakIterator; 31 import dwtx.dwtxhelper.mangoicu.UBreakIterator;
32 import tango.util.collection.ArraySeq; 32 import dwtx.dwtxhelper.Collection;
33 33
34 /** 34 /**
35 * @version 1.0 35 * @version 1.0
36 * @author 36 * @author
37 */ 37 */
45 45
46 protected bool underline; 46 protected bool underline;
47 47
48 private bool wrapAllowed = true; 48 private bool wrapAllowed = true;
49 49
50 protected ArraySeq!(Object) areaRectangles; 50 protected Vector areaRectangles;
51 51
52 private TextFragment[] textFragments; 52 private TextFragment[] textFragments;
53 53
54 class AreaRectangle { 54 class AreaRectangle {
55 Rectangle rect; 55 Rectangle rect;
112 public this(String text, String fontId, String colorId) { 112 public this(String text, String fontId, String colorId) {
113 this(text, fontId, colorId, true); 113 this(text, fontId, colorId, true);
114 } 114 }
115 115
116 public this(String text, String fontId, String colorId, bool wrapAllowed) { 116 public this(String text, String fontId, String colorId, bool wrapAllowed) {
117 areaRectangles = new ArraySeq!(Object); 117 areaRectangles = new Vector();
118 this.text = cleanup(text); 118 this.text = cleanup(text);
119 this.fontId = fontId; 119 this.fontId = fontId;
120 this.colorId = colorId; 120 this.colorId = colorId;
121 this.wrapAllowed = wrapAllowed; 121 this.wrapAllowed = wrapAllowed;
122 } 122 }
341 } 341 }
342 int ly = locator.getBaseline(fm.getHeight() - fm.getLeading()); 342 int ly = locator.getBaseline(fm.getHeight() - fm.getLeading());
343 //int lineY = ly + lineHeight - descent + 1; 343 //int lineY = ly + lineHeight - descent + 1;
344 Rectangle br = new Rectangle(locator.x, ly, ewidth, 344 Rectangle br = new Rectangle(locator.x, ly, ewidth,
345 lineHeight - descent + 3); 345 lineHeight - descent + 3);
346 areaRectangles.append(new AreaRectangle(br, 0, -1)); 346 areaRectangles.add(new AreaRectangle(br, 0, -1));
347 locator.x += ewidth; 347 locator.x += ewidth;
348 locator.width = ewidth; 348 locator.width = ewidth;
349 locator.rowHeight = Math.max(locator.rowHeight, extent.y); 349 locator.rowHeight = Math.max(locator.rowHeight, extent.y);
350 } 350 }
351 351
675 int ly = locator.getBaseline(lineHeight - fm.getLeading()); 675 int ly = locator.getBaseline(lineHeight - fm.getLeading());
676 Rectangle br = new Rectangle(isSelectable()? 676 Rectangle br = new Rectangle(isSelectable()?
677 locator.x - 1:locator.x, ly, 677 locator.x - 1:locator.x, ly,
678 isSelectable()?lineExtent.x + 1:lineExtent.x, lineHeight - descent + 3); 678 isSelectable()?lineExtent.x + 1:lineExtent.x, lineHeight - descent + 3);
679 areaRectangles 679 areaRectangles
680 .append(new AreaRectangle(br, lineStart, lastLoc)); 680 .add(new AreaRectangle(br, lineStart, lastLoc));
681 681
682 locator.rowHeight = Math.max(locator.rowHeight, 682 locator.rowHeight = Math.max(locator.rowHeight,
683 lineExtent.y); 683 lineExtent.y);
684 locator.resetCaret(); 684 locator.resetCaret();
685 if (isSelectable()) 685 if (isSelectable())
702 lastWidth += 1; 702 lastWidth += 1;
703 Rectangle br = new Rectangle(isSelectable()?locator.x - 1:locator.x, ly, 703 Rectangle br = new Rectangle(isSelectable()?locator.x - 1:locator.x, ly,
704 isSelectable()?lineExtent.x + 1:lineExtent.x, 704 isSelectable()?lineExtent.x + 1:lineExtent.x,
705 lineHeight - descent + 3); 705 lineHeight - descent + 3);
706 //int lineY = ly + lineHeight - descent + 1; 706 //int lineY = ly + lineHeight - descent + 1;
707 areaRectangles.append(new AreaRectangle(br, lineStart, lastLoc)); 707 areaRectangles.add(new AreaRectangle(br, lineStart, lastLoc));
708 locator.x += lastWidth; 708 locator.x += lastWidth;
709 locator.rowHeight = Math.max(locator.rowHeight, lineExtent.y); 709 locator.rowHeight = Math.max(locator.rowHeight, lineExtent.y);
710 } 710 }
711 if (oldFont !is null) { 711 if (oldFont !is null) {
712 gc.setFont(oldFont); 712 gc.setFont(oldFont);
714 } 714 }
715 715
716 private void computeTextFragments(GC gc) { 716 private void computeTextFragments(GC gc) {
717 if (textFragments !is null) 717 if (textFragments !is null)
718 return; 718 return;
719 ArraySeq!(Object) list = new ArraySeq!(Object); 719 ArrayList list = new ArrayList();
720 auto wb = UBreakIterator.openLineIterator( ULocale.Default, getText() ); 720 auto wb = UBreakIterator.openLineIterator( ULocale.Default, getText() );
721 scope(exit) wb.close(); 721 scope(exit) wb.close();
722 int cursor = 0; 722 int cursor = 0;
723 for (int loc = wb.first(); loc !is UBreakIterator.Done; loc = wb.next()) { 723 for (int loc = wb.first(); loc !is UBreakIterator.Done; loc = wb.next()) {
724 if (loc is 0) 724 if (loc is 0)
725 continue; 725 continue;
726 String word = text.substring(cursor, loc); 726 String word = text.substring(cursor, loc);
727 Point extent = gc.textExtent(word); 727 Point extent = gc.textExtent(word);
728 list.append(new TextFragment(cast(short) loc, cast(short) extent.x)); 728 list.add(new TextFragment(cast(short) loc, cast(short) extent.x));
729 cursor = loc; 729 cursor = loc;
730 } 730 }
731 textFragments = arraycast!(TextFragment)(list.toArray()); 731 textFragments = arraycast!(TextFragment)(list.toArray());
732 } 732 }
733 733