Mercurial > projects > dwt-addons
comparison dwtx/ui/internal/forms/widgets/FormUtil.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 | 4ac9946b9fb5 |
children | 11e8159caf7a |
comparison
equal
deleted
inserted
replaced
89:040da1cb0d76 | 90:7ffeace6c47f |
---|---|
11 * Port to the D programming language: | 11 * Port to the D programming language: |
12 * Frank Benoit <benoit@tionex.de> | 12 * Frank Benoit <benoit@tionex.de> |
13 *******************************************************************************/ | 13 *******************************************************************************/ |
14 module dwtx.ui.internal.forms.widgets.FormUtil; | 14 module dwtx.ui.internal.forms.widgets.FormUtil; |
15 | 15 |
16 | |
17 // import com.ibm.icu.text.BreakIterator; | |
16 | 18 |
17 import dwt.DWT; | 19 import dwt.DWT; |
18 import dwt.custom.ScrolledComposite; | 20 import dwt.custom.ScrolledComposite; |
19 import dwt.events.MouseEvent; | 21 import dwt.events.MouseEvent; |
20 import dwt.graphics.Device; | 22 import dwt.graphics.Device; |
38 import dwtx.ui.forms.widgets.FormToolkit; | 40 import dwtx.ui.forms.widgets.FormToolkit; |
39 import dwtx.ui.forms.widgets.ILayoutExtension; | 41 import dwtx.ui.forms.widgets.ILayoutExtension; |
40 | 42 |
41 import dwt.dwthelper.utils; | 43 import dwt.dwthelper.utils; |
42 | 44 |
43 //import com.ibm.icu.text.BreakIterator; | 45 import dwtx.dwtxhelper.BreakIterator; |
46 // import mango.icu.UString; | |
47 // import mango.icu.ULocale; | |
48 // import mango.icu.UBreakIterator; | |
49 | |
44 public class FormUtil { | 50 public class FormUtil { |
45 | 51 |
46 //DWT_TODO temp type | |
47 static class BreakIterator{ | |
48 | |
49 public static const int DONE = 0; | |
50 char[] text; | |
51 static BreakIterator inst; | |
52 public static BreakIterator getWordInstance() { | |
53 if( inst is null ){ | |
54 inst = new BreakIterator; | |
55 } | |
56 return inst; | |
57 } | |
58 uint last = 0; | |
59 | |
60 public void setText(String text) { | |
61 this.text = text; | |
62 last = 0; | |
63 } | |
64 public int first() { | |
65 // TODO Auto-generated method stub | |
66 return text.length > 0 ? 1 : 0; | |
67 } | |
68 | |
69 public int next() { | |
70 // TODO Auto-generated method stub | |
71 last++; | |
72 if( last >= text.length ){ | |
73 return DONE; | |
74 } | |
75 return last; | |
76 } | |
77 | |
78 } | |
79 public static const String PLUGIN_ID = "dwtx.ui.forms"; //$NON-NLS-1$ | 52 public static const String PLUGIN_ID = "dwtx.ui.forms"; //$NON-NLS-1$ |
80 | 53 |
81 static const int H_SCROLL_INCREMENT = 5; | 54 static const int H_SCROLL_INCREMENT = 5; |
82 | 55 |
83 static const int V_SCROLL_INCREMENT = 64; | 56 static const int V_SCROLL_INCREMENT = 64; |
136 text.setLayoutData(gd); | 109 text.setLayoutData(gd); |
137 return text; | 110 return text; |
138 } | 111 } |
139 | 112 |
140 public static int computeMinimumWidth(GC gc, String text) { | 113 public static int computeMinimumWidth(GC gc, String text) { |
141 BreakIterator wb = BreakIterator.getWordInstance(); | 114 auto wb = UBreakIterator.openWordIterator( ULocale.Default, text ); |
142 wb.setText(text); | 115 scope(exit) wb.close(); |
143 int last = 0; | 116 int last = 0; |
144 | |
145 int width = 0; | 117 int width = 0; |
146 | 118 |
147 for (int loc = wb.first(); loc !is BreakIterator.DONE; loc = wb.next()) { | 119 for (int loc = wb.first(); loc !is UBreakIterator.DONE; loc = wb.next()) { |
148 String word = text.substring(last, loc); | 120 String word = text.substring(last, loc); |
149 Point extent = gc.textExtent(word); | 121 Point extent = gc.textExtent(word); |
150 width = Math.max(width, extent.x); | 122 width = Math.max(width, extent.x); |
151 last = loc; | 123 last = loc; |
152 } | 124 } |
155 width = Math.max(width, extent.x); | 127 width = Math.max(width, extent.x); |
156 return width; | 128 return width; |
157 } | 129 } |
158 | 130 |
159 public static Point computeWrapSize(GC gc, String text, int wHint) { | 131 public static Point computeWrapSize(GC gc, String text, int wHint) { |
160 BreakIterator wb = BreakIterator.getWordInstance(); | 132 auto wb = UBreakIterator.openWordIterator( ULocale.Default, text ); |
161 wb.setText(text); | 133 scope(exit) wb.close(); |
162 FontMetrics fm = gc.getFontMetrics(); | 134 FontMetrics fm = gc.getFontMetrics(); |
163 int lineHeight = fm.getHeight(); | 135 int lineHeight = fm.getHeight(); |
164 | 136 |
165 int saved = 0; | 137 int saved = 0; |
166 int last = 0; | 138 int last = 0; |
167 int height = lineHeight; | 139 int height = lineHeight; |
168 int maxWidth = 0; | 140 int maxWidth = 0; |
169 for (int loc = wb.first(); loc !is BreakIterator.DONE; loc = wb.next()) { | 141 for (int loc = wb.first(); loc !is UBreakIterator.DONE; loc = wb.next()) { |
170 String word = text.substring(saved, loc); | 142 String word = text.substring(saved, loc); |
171 Point extent = gc.textExtent(word); | 143 Point extent = gc.textExtent(word); |
172 if (extent.x > wHint) { | 144 if (extent.x > wHint) { |
173 // overflow | 145 // overflow |
174 saved = last; | 146 saved = last; |
194 paintWrapText(gc, text, bounds, false); | 166 paintWrapText(gc, text, bounds, false); |
195 } | 167 } |
196 | 168 |
197 public static void paintWrapText(GC gc, String text, Rectangle bounds, | 169 public static void paintWrapText(GC gc, String text, Rectangle bounds, |
198 bool underline) { | 170 bool underline) { |
199 BreakIterator wb = BreakIterator.getWordInstance(); | 171 auto wb = UBreakIterator.openWordIterator( ULocale.Default, text ); |
200 wb.setText(text); | 172 scope(exit) wb.close(); |
201 FontMetrics fm = gc.getFontMetrics(); | 173 FontMetrics fm = gc.getFontMetrics(); |
202 int lineHeight = fm.getHeight(); | 174 int lineHeight = fm.getHeight(); |
203 int descent = fm.getDescent(); | 175 int descent = fm.getDescent(); |
204 | 176 |
205 int saved = 0; | 177 int saved = 0; |
206 int last = 0; | 178 int last = 0; |
207 int y = bounds.y; | 179 int y = bounds.y; |
208 int width = bounds.width; | 180 int width = bounds.width; |
209 | 181 |
210 for (int loc = wb.first(); loc !is BreakIterator.DONE; loc = wb.next()) { | 182 for (int loc = wb.first(); loc !is UBreakIterator.DONE; loc = wb.next()) { |
211 String line = text.substring(saved, loc); | 183 String line = text.substring(saved, loc); |
212 Point extent = gc.textExtent(line); | 184 Point extent = gc.textExtent(line); |
213 | 185 |
214 if (extent.x > width) { | 186 if (extent.x > width) { |
215 // overflow | 187 // overflow |