changeset 154:57cb6d948bf7

Fix visible OBJECT REPLACEMENT CHARACTER. In utf8 length is 2, which needed to be take care of in style.length.
author Frank Benoit <benoit@tionex.de>
date Thu, 21 Aug 2008 18:29:38 +0200
parents 8907b6374258
children 04d05db6dca4
files snippets/styledtext/Snippet212.d
diffstat 1 files changed, 7 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/snippets/styledtext/Snippet212.d	Thu Aug 21 17:49:33 2008 +0200
+++ b/snippets/styledtext/Snippet212.d	Thu Aug 21 18:29:38 2008 +0200
@@ -70,11 +70,13 @@
 import dwt.dwthelper.utils;
 import dwt.dwthelper.System;
 
+const char[] OBJ_MARKER = "\uFFFC";
+
 void main() {
     static StyledText styledText;
     static String text = 
         "This snippet shows how to embed images in a StyledText.\n"
-        "Here is one: \uFFFC, and here is another: \uFFFC."
+        "Here is one: " ~ OBJ_MARKER ~ ", and here is another: " ~ OBJ_MARKER ~ "."
         "Use the add button to add an image from your filesystem to the StyledText at the current caret offset.";
     static Image[] images;
     static int[] offsets;
@@ -82,7 +84,7 @@
     static void addImage(Image image, int offset) {
         StyleRange style = new StyleRange ();
         style.start = offset;
-        style.length = 1;
+        style.length = OBJ_MARKER.length;
         Rectangle rect = image.getBounds();
         style.metrics = new GlyphMetrics(rect.height, 0, rect.width);
         styledText.setStyleRange(style);        
@@ -101,7 +103,7 @@
     offsets = new int[images.length];
     int lastOffset = 0;
     for (int i = 0; i < images.length; i++) {
-        int offset = text.indexOf("\uFFFC", lastOffset);
+        int offset = text.indexOf(OBJ_MARKER, lastOffset);
         offsets[i] = offset;
         addImage(images[i], offset);
         lastOffset = offset + 1;
@@ -162,7 +164,7 @@
             try {
                 Image image = new Image(display, filename);
                 int offset = styledText.getCaretOffset();
-                styledText.replaceTextRange(offset, 0, "\uFFFC");
+                styledText.replaceTextRange(offset, 0, OBJ_MARKER);
                 int index = 0;
                 while (index < offsets.length) {
                     if (offsets[index] == -1 && images[index] is null) break;
@@ -182,7 +184,7 @@
             } catch (Exception e) {
                 ExceptionPrintStackTrace(e);
             }
-        }	        
+        }
     }
     button.addListener(DWT.Selection, dgListener(&onSelection));
     shell.setSize(400, 400);