Mercurial > projects > dwt-addons
comparison dwtx/ui/internal/forms/widgets/Paragraph.d @ 77:26c6c9dfd13c
ui.forms compile, just FormTextModel with xml reimpl left todo
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 24 May 2008 06:59:31 +0200 |
parents | 5d489b9f966c |
children | 7ffeace6c47f |
comparison
equal
deleted
inserted
replaced
76:e193036d82c9 | 77:26c6c9dfd13c |
---|---|
14 | 14 |
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.IHyperlinkSegment; | 17 import dwtx.ui.internal.forms.widgets.IHyperlinkSegment; |
18 import dwtx.ui.internal.forms.widgets.SelectionData; | 18 import dwtx.ui.internal.forms.widgets.SelectionData; |
19 import dwtx.ui.internal.forms.widgets.TextSegment; | |
20 import dwtx.ui.internal.forms.widgets.TextHyperlinkSegment; | |
19 | 21 |
20 import dwt.graphics.GC; | 22 import dwt.graphics.GC; |
21 import dwt.graphics.Rectangle; | 23 import dwt.graphics.Rectangle; |
22 import dwtx.ui.forms.HyperlinkSettings; | 24 import dwtx.ui.forms.HyperlinkSettings; |
23 | 25 |
24 import dwt.dwthelper.utils; | 26 import dwt.dwthelper.utils; |
25 import tango.util.collection.ArraySeq; | 27 import tango.util.collection.ArraySeq; |
26 import tango.util.collection.HashMap; | 28 import tango.util.collection.HashMap; |
29 import tango.io.FileConst; | |
30 import tango.text.Text; | |
27 | 31 |
28 /** | 32 /** |
29 * @version 1.0 | 33 * @version 1.0 |
30 * @author | 34 * @author |
31 */ | 35 */ |
54 /* | 58 /* |
55 * @see IParagraph#getSegments() | 59 * @see IParagraph#getSegments() |
56 */ | 60 */ |
57 public ParagraphSegment[] getSegments() { | 61 public ParagraphSegment[] getSegments() { |
58 if (segments is null) | 62 if (segments is null) |
59 return new TArraySeqParagraphSegment; | 63 return null; |
60 return segments | 64 return segments |
61 .toArray(); | 65 .toArray(); |
62 } | 66 } |
63 | 67 |
64 public void addSegment(ParagraphSegment segment) { | 68 public void addSegment(ParagraphSegment segment) { |
72 parseRegularText(text, expandURLs, wrapAllowed, settings, fontId, null); | 76 parseRegularText(text, expandURLs, wrapAllowed, settings, fontId, null); |
73 } | 77 } |
74 | 78 |
75 public void parseRegularText(String text, bool expandURLs, bool wrapAllowed, | 79 public void parseRegularText(String text, bool expandURLs, bool wrapAllowed, |
76 HyperlinkSettings settings, String fontId, String colorId) { | 80 HyperlinkSettings settings, String fontId, String colorId) { |
77 if (text.length() is 0) | 81 if (text.length is 0) |
78 return; | 82 return; |
79 if (expandURLs) { | 83 if (expandURLs) { |
80 int loc = text.indexOf(HTTP); | 84 int loc = text.indexOf(HTTP); |
81 | 85 |
82 if (loc is -1) | 86 if (loc is -1) |
85 int textLoc = 0; | 89 int textLoc = 0; |
86 while (loc !is -1) { | 90 while (loc !is -1) { |
87 addSegment(new TextSegment(text.substring(textLoc, loc), | 91 addSegment(new TextSegment(text.substring(textLoc, loc), |
88 fontId, colorId, wrapAllowed)); | 92 fontId, colorId, wrapAllowed)); |
89 bool added = false; | 93 bool added = false; |
90 for (textLoc = loc; textLoc < text.length(); textLoc++) { | 94 for (textLoc = loc; textLoc < text.length; textLoc++) { |
91 char c = text.charAt(textLoc); | 95 char c = text.charAt(textLoc); |
92 if (Character.isSpaceChar(c)) { | 96 if (CharacterIsWhitespace(c)) { |
93 addHyperlinkSegment(text.substring(loc, textLoc), | 97 addHyperlinkSegment(text.substring(loc, textLoc), |
94 settings, fontId); | 98 settings, fontId); |
95 added = true; | 99 added = true; |
96 break; | 100 break; |
97 } | 101 } |
102 fontId); | 106 fontId); |
103 break; | 107 break; |
104 } | 108 } |
105 loc = text.indexOf(HTTP, textLoc); | 109 loc = text.indexOf(HTTP, textLoc); |
106 } | 110 } |
107 if (textLoc < text.length()) { | 111 if (textLoc < text.length) { |
108 addSegment(new TextSegment(text.substring(textLoc), fontId, | 112 addSegment(new TextSegment(text.substring(textLoc), fontId, |
109 colorId, wrapAllowed)); | 113 colorId, wrapAllowed)); |
110 } | 114 } |
111 } | 115 } |
112 } else { | 116 } else { |
126 protected void computeRowHeights(GC gc, int width, Locator loc, | 130 protected void computeRowHeights(GC gc, int width, Locator loc, |
127 int lineHeight, Hashtable resourceTable) { | 131 int lineHeight, Hashtable resourceTable) { |
128 ParagraphSegment[] segments = getSegments(); | 132 ParagraphSegment[] segments = getSegments(); |
129 // compute heights | 133 // compute heights |
130 Locator hloc = loc.create(); | 134 Locator hloc = loc.create(); |
131 ArrayList heights = new ArrayList(); | 135 ArraySeq!(ArrayWrapperInt) heights = new ArraySeq!(ArrayWrapperInt); |
132 hloc.heights = heights; | 136 hloc.heights = heights; |
133 hloc.rowCounter = 0; | 137 hloc.rowCounter = 0; |
134 int innerWidth = width - loc.marginWidth*2; | 138 int innerWidth = width - loc.marginWidth*2; |
135 for (int j = 0; j < segments.length; j++) { | 139 for (int j = 0; j < segments.length; j++) { |
136 ParagraphSegment segment = segments[j]; | 140 ParagraphSegment segment = segments[j]; |
155 if (loc.heights is null) | 159 if (loc.heights is null) |
156 computeRowHeights(gc, width, loc, lineHeight, resourceTable); | 160 computeRowHeights(gc, width, loc, lineHeight, resourceTable); |
157 for (int j = 0; j < segments.length; j++) { | 161 for (int j = 0; j < segments.length; j++) { |
158 ParagraphSegment segment = segments[j]; | 162 ParagraphSegment segment = segments[j]; |
159 bool doSelect = false; | 163 bool doSelect = false; |
160 if (selectedLink !is null && segment.equals(selectedLink)) | 164 if (selectedLink !is null && segment.opEquals(cast(Object)selectedLink)) |
161 doSelect = true; | 165 doSelect = true; |
162 segment.layout(gc, width, loc, resourceTable, doSelect); | 166 segment.layout(gc, width, loc, resourceTable, doSelect); |
163 } | 167 } |
164 loc.heights = null; | 168 loc.heights = null; |
165 loc.y += loc.rowHeight; | 169 loc.y += loc.rowHeight; |
176 for (int i = 0; i < segments.length; i++) { | 180 for (int i = 0; i < segments.length; i++) { |
177 ParagraphSegment segment = segments[i]; | 181 ParagraphSegment segment = segments[i]; |
178 if (!segment.intersects(repaintRegion)) | 182 if (!segment.intersects(repaintRegion)) |
179 continue; | 183 continue; |
180 bool doSelect = false; | 184 bool doSelect = false; |
181 if (selectedLink !is null && segment.equals(selectedLink)) | 185 if (selectedLink !is null && segment.opEquals(cast(Object)selectedLink)) |
182 doSelect = true; | 186 doSelect = true; |
183 segment.paint(gc, false, resourceTable, doSelect, selData, repaintRegion); | 187 segment.paint(gc, false, resourceTable, doSelect, selData, repaintRegion); |
184 } | 188 } |
185 } | 189 } |
186 | 190 |
197 } | 201 } |
198 } | 202 } |
199 | 203 |
200 public String getAccessibleText() { | 204 public String getAccessibleText() { |
201 ParagraphSegment[] segments = getSegments(); | 205 ParagraphSegment[] segments = getSegments(); |
202 StringWriter swriter = new StringWriter(); | 206 auto txt = new tango.text.Text.Text!(char); |
203 PrintWriter writer = new PrintWriter(swriter); | |
204 for (int i = 0; i < segments.length; i++) { | 207 for (int i = 0; i < segments.length; i++) { |
205 ParagraphSegment segment = segments[i]; | 208 ParagraphSegment segment = segments[i]; |
206 if ( auto ts = cast(TextSegment)segment ) { | 209 if ( auto ts = cast(TextSegment)segment ) { |
207 String text = ts.getText(); | 210 String text = ts.getText(); |
208 writer.print(text); | 211 txt.append(text); |
209 } | 212 } |
210 } | 213 } |
211 writer.println(); | 214 txt.append( FileConst.NewlineString ); |
212 swriter.flush(); | 215 return txt.toString(); |
213 return swriter.toString(); | |
214 } | 216 } |
215 | 217 |
216 public ParagraphSegment findSegmentAt(int x, int y) { | 218 public ParagraphSegment findSegmentAt(int x, int y) { |
217 if (segments !is null) { | 219 if (segments !is null) { |
218 for (int i = 0; i < segments.size(); i++) { | 220 for (int i = 0; i < segments.size(); i++) { |