Mercurial > projects > dwt-addons
comparison dwtx/ui/internal/forms/widgets/TextSegment.d @ 90:7ffeace6c47f
Update 3.4M7 to 3.4
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 06 Jul 2008 23:30:07 +0200 |
parents | 26c6c9dfd13c |
children | 11e8159caf7a |
comparison
equal
deleted
inserted
replaced
89:040da1cb0d76 | 90:7ffeace6c47f |
---|---|
1 /******************************************************************************* | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2007 IBM Corporation and others. | 2 * Copyright (c) 2000, 2008 IBM Corporation and others. |
3 * All rights reserved. This program and the accompanying materials | 3 * All rights reserved. This program and the accompanying materials |
4 * are made available under the terms of the Eclipse Public License v1.0 | 4 * are made available under the terms of the Eclipse Public License v1.0 |
5 * which accompanies this distribution, and is available at | 5 * which accompanies this distribution, and is available at |
6 * http://www.eclipse.org/legal/epl-v10.html | 6 * http://www.eclipse.org/legal/epl-v10.html |
7 * | 7 * |
15 import dwtx.ui.internal.forms.widgets.ParagraphSegment; | 15 import dwtx.ui.internal.forms.widgets.ParagraphSegment; |
16 import dwtx.ui.internal.forms.widgets.Locator; | 16 import dwtx.ui.internal.forms.widgets.Locator; |
17 import dwtx.ui.internal.forms.widgets.SelectionData; | 17 import dwtx.ui.internal.forms.widgets.SelectionData; |
18 import dwtx.ui.internal.forms.widgets.FormTextModel; | 18 import dwtx.ui.internal.forms.widgets.FormTextModel; |
19 | 19 |
20 // import com.ibm.icu.text.BreakIterator; | |
21 | |
20 import dwt.DWT; | 22 import dwt.DWT; |
21 import dwt.graphics.Color; | 23 import dwt.graphics.Color; |
22 import dwt.graphics.Font; | 24 import dwt.graphics.Font; |
23 import dwt.graphics.FontMetrics; | 25 import dwt.graphics.FontMetrics; |
24 import dwt.graphics.GC; | 26 import dwt.graphics.GC; |
25 import dwt.graphics.Point; | 27 import dwt.graphics.Point; |
26 import dwt.graphics.Rectangle; | 28 import dwt.graphics.Rectangle; |
27 | 29 |
28 import dwt.dwthelper.utils; | 30 import dwt.dwthelper.utils; |
31 // import mango.icu.ULocale; | |
32 // import mango.icu.UString; | |
33 // import mango.icu.UBreakIterator; | |
34 import dwtx.dwtxhelper.BreakIterator; | |
29 import tango.util.collection.ArraySeq; | 35 import tango.util.collection.ArraySeq; |
30 | 36 |
31 /** | 37 /** |
32 * @version 1.0 | 38 * @version 1.0 |
33 * @author | 39 * @author |
34 */ | 40 */ |
35 public class TextSegment : ParagraphSegment { | 41 public class TextSegment : ParagraphSegment { |
36 | 42 |
37 //DWT_TODO temp type | |
38 static class BreakIterator{ | |
39 | |
40 public static const int DONE = 0; | |
41 | |
42 public static BreakIterator getLineInstance() { | |
43 // TODO Auto-generated method stub | |
44 return null; | |
45 } | |
46 | |
47 public void setText(String text) { | |
48 // TODO Auto-generated method stub | |
49 | |
50 } | |
51 | |
52 public int first() { | |
53 // TODO Auto-generated method stub | |
54 return 0; | |
55 } | |
56 | |
57 public int next() { | |
58 // TODO Auto-generated method stub | |
59 return 0; | |
60 } | |
61 | |
62 } | |
63 private String colorId; | 43 private String colorId; |
64 | 44 |
65 private String fontId; | 45 private String fontId; |
66 | 46 |
67 private String text; | 47 private String text; |
302 int currentExtent = locator.x + lineExtent.x; | 282 int currentExtent = locator.x + lineExtent.x; |
303 | 283 |
304 if (isSelectable()) | 284 if (isSelectable()) |
305 currentExtent += 1; | 285 currentExtent += 1; |
306 | 286 |
307 if (i !is 0 && currentExtent + textFragment.length > wHint) { | 287 // i !is 0 || locator.x > locator.getStartX() + (isSelectable() ? 1 : 0) means: |
288 // only wrap on the first fragment if we are not at the start of a line | |
289 if ((i !is 0 || locator.x > locator.getStartX() + (isSelectable() ? 1 : 0)) && currentExtent + textFragment.length > wHint) { | |
308 // overflow | 290 // overflow |
309 int lineWidth = currentExtent; | 291 int lineWidth = currentExtent; |
310 locator.rowHeight = Math.max(locator.rowHeight, lineExtent.y); | 292 locator.rowHeight = Math.max(locator.rowHeight, lineExtent.y); |
311 locator.leading = Math.max(locator.leading, fm.getLeading()); | 293 locator.leading = Math.max(locator.leading, fm.getLeading()); |
312 if (computeHeightOnly) | 294 if (computeHeightOnly) |
621 if (rolloverMode && !hover) | 603 if (rolloverMode && !hover) |
622 reverse = true; | 604 reverse = true; |
623 } | 605 } |
624 if (reverse) { | 606 if (reverse) { |
625 drawUnderline(gc, swidth, clipX, clipLineY, hover, rolloverMode); | 607 drawUnderline(gc, swidth, clipX, clipLineY, hover, rolloverMode); |
626 gc.drawString(s, clipX, clipY, false); | 608 drawString(gc, s, clipX, clipY); |
627 } else { | 609 } else { |
628 gc.drawString(s, clipX, clipY, false); | 610 drawString(gc, s, clipX, clipY); |
629 drawUnderline(gc, swidth, clipX, clipLineY, hover, rolloverMode); | 611 drawUnderline(gc, swidth, clipX, clipLineY, hover, rolloverMode); |
630 } | 612 } |
613 } | |
614 | |
615 protected void drawString(GC gc, String s, int clipX, int clipY) { | |
616 gc.drawString(s, clipX, clipY, true); | |
631 } | 617 } |
632 | 618 |
633 private void drawUnderline(GC gc, int swidth, int x, int y, bool hover, | 619 private void drawUnderline(GC gc, int swidth, int x, int y, bool hover, |
634 bool rolloverMode) { | 620 bool rolloverMode) { |
635 if (underline || hover || rolloverMode) { | 621 if (underline || hover || rolloverMode) { |
680 for (int i = 0; i < textFragments.length; i++) { | 666 for (int i = 0; i < textFragments.length; i++) { |
681 TextFragment fragment = textFragments[i]; | 667 TextFragment fragment = textFragments[i]; |
682 int breakLoc = fragment.index; | 668 int breakLoc = fragment.index; |
683 if (breakLoc is 0) | 669 if (breakLoc is 0) |
684 continue; | 670 continue; |
685 if (i !is 0 && locator.x + lineExtent.x + fragment.length > rightEdge) { | 671 // (i !is 0 || locator.x > locator.getStartX() + (isSelectable() ? 1 : 0)) means: |
672 // only wrap on the first fragment if we are not at the start of a line | |
673 if ((i !is 0 || locator.x > locator.getStartX() + (isSelectable() ? 1 : 0)) && locator.x + lineExtent.x + fragment.length > rightEdge) { | |
686 // overflow | 674 // overflow |
687 int lineWidth = locator.x + lineExtent.x; | 675 int lineWidth = locator.x + lineExtent.x; |
688 if (isSelectable()) | 676 if (isSelectable()) |
689 lineWidth += 1; | 677 lineWidth += 1; |
690 int ly = locator.getBaseline(lineHeight - fm.getLeading()); | 678 int ly = locator.getBaseline(lineHeight - fm.getLeading()); |
730 | 718 |
731 private void computeTextFragments(GC gc) { | 719 private void computeTextFragments(GC gc) { |
732 if (textFragments !is null) | 720 if (textFragments !is null) |
733 return; | 721 return; |
734 ArraySeq!(Object) list = new ArraySeq!(Object); | 722 ArraySeq!(Object) list = new ArraySeq!(Object); |
735 BreakIterator wb = BreakIterator.getLineInstance(); | 723 auto wb = UBreakIterator.openLineIterator( ULocale.Default, getText() ); |
736 wb.setText(getText()); | 724 scope(exit) wb.close(); |
737 int cursor = 0; | 725 int cursor = 0; |
738 for (int loc = wb.first(); loc !is BreakIterator.DONE; loc = wb.next()) { | 726 for (int loc = wb.first(); loc !is UBreakIterator.DONE; loc = wb.next()) { |
739 if (loc is 0) | 727 if (loc is 0) |
740 continue; | 728 continue; |
741 String word = text.substring(cursor, loc); | 729 String word = text.substring(cursor, loc); |
742 Point extent = gc.textExtent(word); | 730 Point extent = gc.textExtent(word); |
743 list.append(new TextFragment(cast(short) loc, cast(short) extent.x)); | 731 list.append(new TextFragment(cast(short) loc, cast(short) extent.x)); |