Changeset 154:57cb6d948bf7
- Timestamp:
- 08/21/08 12:29:38
(3 months ago)
- Author:
- Frank Benoit <benoit@tionex.de>
- branch:
- default
- Message:
Fix visible OBJECT REPLACEMENT CHARACTER. In utf8 length is 2, which needed to be take care of in style.length.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r150 |
r154 |
|
| 71 | 71 | import dwt.dwthelper.System; |
|---|
| 72 | 72 | |
|---|
| | 73 | const char[] OBJ_MARKER = "\uFFFC"; |
|---|
| | 74 | |
|---|
| 73 | 75 | void main() { |
|---|
| 74 | 76 | static StyledText styledText; |
|---|
| 75 | 77 | static String text = |
|---|
| 76 | 78 | "This snippet shows how to embed images in a StyledText.\n" |
|---|
| 77 | | "Here is one: \uFFFC, and here is another: \uFFFC." |
|---|
| | 79 | "Here is one: " ~ OBJ_MARKER ~ ", and here is another: " ~ OBJ_MARKER ~ "." |
|---|
| 78 | 80 | "Use the add button to add an image from your filesystem to the StyledText at the current caret offset."; |
|---|
| 79 | 81 | static Image[] images; |
|---|
| … | … | |
| 83 | 85 | StyleRange style = new StyleRange (); |
|---|
| 84 | 86 | style.start = offset; |
|---|
| 85 | | style.length = 1; |
|---|
| | 87 | style.length = OBJ_MARKER.length; |
|---|
| 86 | 88 | Rectangle rect = image.getBounds(); |
|---|
| 87 | 89 | style.metrics = new GlyphMetrics(rect.height, 0, rect.width); |
|---|
| … | … | |
| 102 | 104 | int lastOffset = 0; |
|---|
| 103 | 105 | for (int i = 0; i < images.length; i++) { |
|---|
| 104 | | int offset = text.indexOf("\uFFFC", lastOffset); |
|---|
| | 106 | int offset = text.indexOf(OBJ_MARKER, lastOffset); |
|---|
| 105 | 107 | offsets[i] = offset; |
|---|
| 106 | 108 | addImage(images[i], offset); |
|---|
| … | … | |
| 163 | 165 | Image image = new Image(display, filename); |
|---|
| 164 | 166 | int offset = styledText.getCaretOffset(); |
|---|
| 165 | | styledText.replaceTextRange(offset, 0, "\uFFFC"); |
|---|
| | 167 | styledText.replaceTextRange(offset, 0, OBJ_MARKER); |
|---|
| 166 | 168 | int index = 0; |
|---|
| 167 | 169 | while (index < offsets.length) { |
|---|
| … | … | |
| 183 | 185 | ExceptionPrintStackTrace(e); |
|---|
| 184 | 186 | } |
|---|
| 185 | | } |
|---|
| | 187 | } |
|---|
| 186 | 188 | } |
|---|
| 187 | 189 | button.addListener(DWT.Selection, dgListener(&onSelection)); |
|---|