Changeset 154:57cb6d948bf7

Show
Ignore:
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
  • snippets/styledtext/Snippet212.d

    r150 r154  
    7171import dwt.dwthelper.System; 
    7272 
     73const char[] OBJ_MARKER = "\uFFFC"; 
     74 
    7375void main() { 
    7476    static StyledText styledText; 
    7577    static String text =  
    7678        "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 ~ "." 
    7880        "Use the add button to add an image from your filesystem to the StyledText at the current caret offset."; 
    7981    static Image[] images; 
     
    8385        StyleRange style = new StyleRange (); 
    8486        style.start = offset; 
    85         style.length = 1
     87        style.length = OBJ_MARKER.length
    8688        Rectangle rect = image.getBounds(); 
    8789        style.metrics = new GlyphMetrics(rect.height, 0, rect.width); 
     
    102104    int lastOffset = 0; 
    103105    for (int i = 0; i < images.length; i++) { 
    104         int offset = text.indexOf("\uFFFC", lastOffset); 
     106        int offset = text.indexOf(OBJ_MARKER, lastOffset); 
    105107        offsets[i] = offset; 
    106108        addImage(images[i], offset); 
     
    163165                Image image = new Image(display, filename); 
    164166                int offset = styledText.getCaretOffset(); 
    165                 styledText.replaceTextRange(offset, 0, "\uFFFC"); 
     167                styledText.replaceTextRange(offset, 0, OBJ_MARKER); 
    166168                int index = 0; 
    167169                while (index < offsets.length) { 
     
    183185                ExceptionPrintStackTrace(e); 
    184186            } 
    185         }           
     187        } 
    186188    } 
    187189    button.addListener(DWT.Selection, dgListener(&onSelection));