Changeset 274:62a03a4c21c8

Show
Ignore:
Timestamp:
08/03/08 17:40:57 (4 months ago)
Author:
Frank Benoit <benoit@tionex.de>
branch:
default
Message:

sync StyledText? with dwt-linux

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • dwt/custom/DefaultContent.d

    r264 r274  
    2222import dwt.custom.StyledTextListener; 
    2323import dwt.custom.StyledText; 
     24import dwt.dwthelper.utils; 
    2425 
    2526static import tango.io.model.IFile; 
    2627static import tango.text.Text; 
    27 import dwt.dwthelper.utils; 
    2828 
    2929alias tango.text.Text.Text!(char) StringBuffer; 
     
    3333 
    3434    StyledTextListener[] textListeners; // stores text listeners for event sending 
    35     String textStore; // stores the actual text 
     35    char[] textStore; // stores the actual text 
    3636    int gapStart = -1;  // the character position start of the gap 
    3737    int gapEnd = -1;    // the character position after the end of the gap 
     
    735735 * 
    736736 * @param listener the listener which should no longer be notified 
    737  *  
     737 * 
    738738 * @exception IllegalArgumentException <ul> 
    739739 *    <li>ERROR_NULL_ARGUMENT when listener is null</li> 
     
    892892    gapLine = getLineAtPhysicalOffset(gapStart); 
    893893} 
    894 
     894 
     895/++ 
     896 + DWT extension 
     897 +/ 
     898int utf8AdjustOffset( int offset ){ 
     899    if (textStore is null) 
     900        return offset; 
     901    if (offset is 0) 
     902        return offset; 
     903    if( offset >= textStore.length ){ 
     904        return offset; 
     905    } 
     906    if (!gapExists() || (offset < gapStart)){ 
     907        while( textStore[offset] & 0xC0 is 0x80 ){ 
     908            offset--; 
     909        } 
     910        return offset; 
     911    } 
     912    int gapLength= gapEnd - gapStart; 
     913    if( offset+gapLength >= textStore.length ){ 
     914        return offset; 
     915    } 
     916    while( textStore[offset+gapLength] & 0xC0 is 0x80 ){ 
     917        offset--; 
     918    } 
     919    return offset; 
     920
     921 
     922 
     923
  • dwt/custom/StyleRange.d

    r255 r274  
    1212 *******************************************************************************/ 
    1313module dwt.custom.StyleRange; 
     14 
     15import dwt.dwthelper.utils; 
    1416 
    1517 
     
    2123import dwt.custom.TextChangedEvent; 
    2224import dwt.custom.TextChangingEvent; 
    23 import dwt.dwthelper.utils; 
    2425 
    2526static import tango.text.Text; 
     
    6667public this() { 
    6768} 
     69/++ 
     70 + DWT extension for clone implementation 
     71 +/ 
     72protected this( StyleRange other ){ 
     73    super( other ); 
     74    start = other.start; 
     75    length = other.length; 
     76    fontStyle = other.fontStyle; 
     77} 
    6878 
    6979/** 
     
    7484 * @since 3.4 
    7585 */ 
    76 public this(StyleRange style) { 
    77     this( cast(TextStyle)style); 
    78     this.start = style.start; 
    79     this.length = style.length; 
    80     this.fontStyle = style.fontStyle; 
    81 } 
    8286public this(TextStyle style) { 
    8387    super(style); 
  • dwt/custom/StyledText.d

    r264 r274  
    150150 */ 
    151151public class StyledText : Canvas { 
    152  
    153152    alias Canvas.computeSize computeSize; 
    154153 
     
    627626        int lastSegmentIndex = 0; 
    628627        for (int i = 0; i < 3; i++) { 
    629             int segmentIndex = tango.text.Util.locatePattern( text, StyledTextPrintOptions.SEPARATOR, lastSegmentIndex); 
     628            int segmentIndex = text.indexOf( StyledTextPrintOptions.SEPARATOR, lastSegmentIndex); 
    630629            String segment; 
    631             if (segmentIndex is text.length ) { 
    632                 segment = text[ lastSegmentIndex .. $ ].dup
     630            if (segmentIndex is -1 ) { 
     631                segment = text.substring(lastSegmentIndex)
    633632                printDecorationSegment(segment, i, page, header, layout); 
    634633                break; 
    635634            } else { 
    636                 segment = text[ lastSegmentIndex .. segmentIndex ].dup
     635                segment = text.substring(lastSegmentIndex, segmentIndex)
    637636                printDecorationSegment(segment, i, page, header, layout); 
    638637                lastSegmentIndex = segmentIndex + StyledTextPrintOptions.SEPARATOR.length; 
     
    651650     */ 
    652651    void printDecorationSegment(String segment, int alignment, int page, bool header, TextLayout layout) { 
    653         int pageIndex = tango.text.Util.locatePattern( segment, StyledTextPrintOptions.PAGE_TAG ); 
    654         if (pageIndex !is segment.length ) { 
     652        int pageIndex = segment.indexOf(StyledTextPrintOptions.PAGE_TAG); 
     653        if (pageIndex !is -1 ) { 
    655654            int pageTagLength = StyledTextPrintOptions.PAGE_TAG.length; 
    656             StringBuffer buffer = new StringBuffer(segment[ 0 .. pageIndex ]); 
     655            StringBuffer buffer = new StringBuffer(segment.substring (0, pageIndex)); 
    657656            buffer.append (page); 
    658             buffer.append (segment[ pageIndex + pageTagLength .. $ ]); 
     657            buffer.append (segment.substring(pageIndex + pageTagLength)); 
    659658            segment = buffer.toString().dup; 
    660659        } 
     
    706705                } 
    707706            } else { 
    708                 printLayout.setText( to!(String)(index) ); 
     707                printLayout.setText(to!(String)(index)); 
    709708            } 
    710709            int paintX = x - printMargin - printLayout.getBounds().width; 
     
    871870     */ 
    872871    void write(String string, int start, int end) { 
    873         wchar[] wstring = tango.text.convert.Utf.toString16( string[ start .. end ] ); 
    874872        start = 0; 
    875         end = wstring.length; 
    876         for (int index = start; index < end; index++) { 
    877             wchar ch = wstring[index]; 
     873        end = string.length; 
     874        int incr = 1; 
     875        for (int index = start; index < end; index+=incr) { 
     876            dchar ch = firstCodePoint( string[index .. $], incr ); 
    878877            if (ch > 0xFF && WriteUnicode) { 
    879878                // write the sub string from the last escaped character 
    880879                // to the current one. Fixes bug 21698. 
    881880                if (index > start) { 
    882                     write(tango.text.convert.Utf.toString(wstring[start .. index ])); 
     881                    write( string[start .. index ] ); 
    883882                } 
    884883                write("\\u"); 
    885884                write( to!(String)( cast(short)ch )); 
    886885                write(' ');                     // control word delimiter 
    887                 start = index + 1
     886                start = index + incr
    888887            } else if (ch is '}' || ch is '{' || ch is '\\') { 
    889888                // write the sub string from the last escaped character 
    890889                // to the current one. Fixes bug 21698. 
    891890                if (index > start) { 
    892                     write(tango.text.convert.Utf.toString(wstring[start .. index])); 
     891                    write(string[start .. index]); 
    893892                } 
    894893                write('\\'); 
     
    900899        // Fixes bug 21698. 
    901900        if (start < end) { 
    902             write(tango.text.convert.Utf.toString(wstring[ start .. end])); 
     901            write(string[ start .. end]); 
    903902        } 
    904903    } 
     
    12701269        int copyEnd = Math.min(lineLength, endOffset - lineOffset); 
    12711270        if (lineIndex < copyEnd) { 
    1272             write(line[lineIndex .. copyEnd]); 
     1271            write(line.substring(lineIndex, copyEnd)); 
    12731272        } 
    12741273    } 
     
    16041603 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 
    16051604 * </ul> 
    1606  * @exception IllegalArgumentException <ul> 
    1607  *    <li>ERROR_NULL_ARGUMENT when listener is null</li> 
    1608  * </ul> 
    16091605 */ 
    16101606public void append(String string) { 
    16111607    checkWidget(); 
    1612     // DWT extension: allow null string 
    1613     //if (string is null) { 
    1614     //    DWT.error(DWT.ERROR_NULL_ARGUMENT); 
    1615     //
     1608    // DWT extension: allow null for zero length string 
     1609//     if (string is null) { 
     1610//         DWT.error(DWT.ERROR_NULL_ARGUMENT); 
     1611//     
    16161612    int lastChar = Math.max(getCharCount(), 0); 
    16171613    replaceTextRange(lastChar, 0, string); 
     
    19381934    while (i < length) { 
    19391935        if (crIndex !is -1) { 
    1940             crIndex = tango.text.Util.locate( text, DWT.CR, i); 
    1941             if( crIndex is text.length ) crIndex = -1; 
     1936            crIndex = text.indexOf (DWT.CR, i); 
    19421937        } 
    19431938        if (lfIndex !is -1) { 
    1944             lfIndex = tango.text.Util.locate( text, DWT.LF, i); 
    1945             if( lfIndex is text.length ) lfIndex = -1; 
     1939            lfIndex = text.indexOf (DWT.LF, i); 
    19461940        } 
    19471941        if (lfIndex is -1 && crIndex is -1) {   // no more line breaks? 
    19481942            break; 
    19491943        } else if ((crIndex < lfIndex && crIndex !is -1) || lfIndex is -1) { 
    1950             convertedText.append(text[i .. crIndex]); 
     1944            convertedText.append(text.substring(i, crIndex)); 
    19511945            if (lfIndex is crIndex + 1) {       // CR/LF combination? 
    19521946                i = lfIndex + 1; 
     
    19551949            } 
    19561950        } else {                                    // LF occurs before CR! 
    1957             convertedText.append(text[i .. lfIndex]); 
     1951            convertedText.append(text.substring(i, lfIndex)); 
    19581952            i = lfIndex + 1; 
    19591953        } 
     
    19661960    // text copied thus far (because there only is one line) 
    19671961    if (i < length && (!isSingleLine() || convertedText.length() is 0)) { 
    1968         convertedText.append(text[i .. $]); 
     1962        convertedText.append(text.substring(i)); 
    19691963    } 
    19701964    return convertedText.toString(); 
     
    20782072    Display display = getDisplay(); 
    20792073    if (leftCaretBitmap !is null) { 
    2080         if (defaultCaret !is null && leftCaretBitmap==defaultCaret.getImage()) { 
     2074        if (defaultCaret !is null && leftCaretBitmap==/*eq*/defaultCaret.getImage()) { 
    20812075            defaultCaret.setImage(null); 
    20822076        } 
     
    20952089 
    20962090    if (rightCaretBitmap !is null) { 
    2097         if (defaultCaret !is null && rightCaretBitmap==defaultCaret.getImage()) { 
     2091        if (defaultCaret !is null && rightCaretBitmap==/*eq*/defaultCaret.getImage()) { 
    20982092            defaultCaret.setImage(null); 
    20992093        } 
     
    22702264 * @param key the character typed by the user 
    22712265 */ 
    2272 void doContent(char key) { 
     2266void doContent(dchar key) { 
    22732267    Event event = new Event(); 
    22742268    event.start = selection.x; 
     
    22902284        // end of the line 
    22912285        if (event.end < lineOffset + line.length) { 
    2292             event.end++
    2293         } 
    2294         event.text = [key]
     2286            event.end+=dcharToString( key ).length
     2287        } 
     2288        event.text = dcharToString( key )
    22952289    } else { 
    2296         event.text = [key]
     2290        event.text = dcharToString( key )
    22972291    } 
    22982292    if (event.text !is null) { 
     
    26012595/** 
    26022596 * Returns the offset of the word at the specified offset. 
    2603  * If the current selection : from high index to low index 
     2597 * If the current selection extends from high index to low index 
    26042598 * (i.e., right to left, or caret is at left border of selection on 
    26052599 * non-bidi platforms) the start offset of the word preceding the 
    2606  * selection is returned. If the current selection : from 
     2600 * selection is returned. If the current selection extends from 
    26072601 * low index to high index the end offset of the word following 
    26082602 * the selection is returned. 
     
    30103004    int offsetInLine = caretOffset - lineOffset; 
    30113005    caretAlignment = OFFSET_LEADING; 
     3006 
    30123007    if (offsetInLine > 0) { 
    30133008        caretOffset = getClusterPrevious(caretOffset, caretLine); 
     
    33653360} 
    33663361/** 
    3367  * Returns whether the widget : double click mouse behavior. 
     3362 * Returns whether the widget implements double click mouse behavior. 
    33683363 * 
    33693364 * @return true if double clicking a word selects the word, false if double clicks 
     
    38303825 * 
    38313826 * @return the top pixel of a given line index 
    3832  *  
     3827 * 
    38333828 * @since 3.2 
    38343829 */ 
     
    38573852 * Returns the line index for a y, relative to the client area. 
    38583853 * The line index returned is always in the range 0..lineCount - 1. 
    3859  *  
     3854 * 
    38603855 * @param y the y-coordinate pixel 
    3861  *  
     3856 * 
    38623857 * @return the line index for a given y-coordinate pixel 
    38633858 * 
     
    49514946public void insert(String string) { 
    49524947    checkWidget(); 
    4953     // DWT extension: allow null string 
    4954     //if (string is null) { 
    4955     //    DWT.error(DWT.ERROR_NULL_ARGUMENT); 
    4956     //
     4948    // DWT extension: allow null for zero length string 
     4949//     if (string is null) { 
     4950//         DWT.error(DWT.ERROR_NULL_ARGUMENT); 
     4951//     
    49574952    Point sel = getSelectionRange(); 
    49584953    replaceTextRange(sel.x, sel.y, string); 
     
    50085003    addListener(DWT.Resize, listener); 
    50095004    addListener(DWT.Traverse, listener); 
    5010     ime.addListener(DWT.ImeComposition, new class () Listener { 
     5005    ime.addListener(DWT.ImeComposition, new class() Listener { 
    50115006        public void handleEvent(Event event) { 
    50125007            switch (event.detail) { 
     
    57285723        if (++index >= length_) return string; 
    57295724        if (string[index] !is '&') { 
    5730             return string[0 .. index-1] ~ string[index .. length_]
     5725            return string.substring(0, index-1) ~ string.substring(index, length_)
    57315726        } 
    57325727        index++; 
     
    57465741        while (index < length_ && string[index] !is '&') index++; 
    57475742        if (++index >= length_) return '\0'; 
    5748         if (string[index] !is '&') return CharacterToLower(firstCodePoint( string[index .. $ ] )); 
     5743        if (string[index] !is '&') return CharacterFirstToLower(string[index .. $ ] ); 
    57495744        index++; 
    57505745    } while (index < length_); 
     
    62726267 * 
    62736268 * @param listener the listener which should no longer be notified 
    6274  *  
     6269 * 
    62756270 * @exception DWTException <ul> 
    62766271 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 
     
    62806275 *    <li>ERROR_NULL_ARGUMENT when listener is null</li> 
    62816276 * </ul> 
    6282  *  
     6277 * 
    62836278 * @since 2.0 
    62846279 */ 
     
    63106305 * 
    63116306 * @param listener the listener which should no longer be notified 
    6312  *  
     6307 * 
    63136308 * @exception DWTException <ul> 
    63146309 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 
     
    63286323 * 
    63296324 * @param listener the listener which should no longer be notified 
    6330  *  
     6325 * 
    63316326 * @exception DWTException <ul> 
    63326327 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 
     
    63466341 * 
    63476342 * @param modifyListener the listener which should no longer be notified 
    6348  *  
     6343 * 
    63496344 * @exception DWTException <ul> 
    63506345 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 
     
    63646359 * 
    63656360 * @param listener the listener which should no longer be notified 
    6366  *  
     6361 * 
    63676362 * @exception DWTException <ul> 
    63686363 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 
     
    64056400 * 
    64066401 * @param verifyListener the listener which should no longer be notified 
    6407  *  
     6402 * 
    64086403 * @exception DWTException <ul> 
    64096404 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 
     
    64236418 * 
    64246419 * @param listener the listener which should no longer be notified 
    6425  *  
     6420 * 
    64266421 * @exception DWTException <ul> 
    64276422 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 
     
    64406435 * 
    64416436 * @param listener the listener which should no longer be notified 
    6442  *  
     6437 * 
    64436438 * @exception DWTException <ul> 
    64446439 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 
     
    64986493    checkWidget(); 
    64996494    if (isListening(LineGetStyle)) return; 
    6500     // DWT extension: allow null array 
     6495    // DWT extension: allow null for zero length string 
    65016496    //if (ranges is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 
    65026497    setStyleRanges(start, length, null, ranges, false); 
     
    65366531public void replaceTextRange(int start, int length, String text) { 
    65376532    checkWidget(); 
    6538     // DWT extension: allow null string 
    6539     //if (text is null) { 
    6540     //    DWT.error(DWT.ERROR_NULL_ARGUMENT); 
    6541     //
     6533    // DWT extension: allow null for zero length string 
     6534//     if (text is null) { 
     6535//         DWT.error(DWT.ERROR_NULL_ARGUMENT); 
     6536//     
    65426537    int contentLength = getCharCount(); 
    65436538    int end = start + length; 
     
    78297824void setSelection(int start, int length, bool sendEvent) { 
    78307825    int end = start + length; 
     7826    start = content.utf8AdjustOffset(start); 
     7827    end = content.utf8AdjustOffset(end); 
    78317828    if (start > end) { 
    78327829        int temp = end; 
     
    79527949 * </ul> 
    79537950 * @exception IllegalArgumentException <ul> 
     7951 *    <li>ERROR_NULL_ARGUMENT when an element in the styles array is null</li> 
    79547952 *    <li>ERROR_INVALID_RANGE when the number of ranges and style do not match (ranges.length * 2 is styles.length)</li> 
    79557953 *    <li>ERROR_INVALID_RANGE when a range is outside the valid range (> getCharCount() or less than zero)</li> 
     
    79937991 * </ul> 
    79947992 * @exception IllegalArgumentException <ul> 
     7993 *    <li>ERROR_NULL_ARGUMENT when an element in the styles array is null</li> 
    79957994 *    <li>ERROR_INVALID_RANGE when the number of ranges and style do not match (ranges.length * 2 is styles.length)</li> 
    79967995 *    <li>ERROR_INVALID_RANGE when a range is outside the valid range (> getCharCount() or less than zero)</li> 
     
    81288127    checkWidget(); 
    81298128    if (isListening(LineGetStyle)) return; 
    8130     // DWT extension: allow null array 
     8129    // DWT extension: allow null for zero length string 
    81318130    //if (ranges is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 
    81328131    setStyleRanges(0, 0, null, ranges, true); 
     
    81708169public void setText(String text) { 
    81718170    checkWidget(); 
    8172     // DWT extension: allow null string 
    8173     //if (text is null) { 
    8174     //    DWT.error(DWT.ERROR_NULL_ARGUMENT); 
    8175     //
     8171    // DWT extension: allow null for zero length string 
     8172//     if (text is null) { 
     8173//         DWT.error(DWT.ERROR_NULL_ARGUMENT); 
     8174//     
    81768175    Event event = new Event(); 
    81778176    event.start = 0; 
  • dwt/custom/StyledTextContent.d

    r246 r274  
    1313module dwt.custom.StyledTextContent; 
    1414 
     15import dwt.dwthelper.utils; 
     16 
    1517import dwt.custom.TextChangeListener; 
    16 import dwt.dwthelper.utils; 
    17  
    1818/** 
    1919 * Clients may implement the StyledTextContent interface to provide a 
     
    144144 * 
    145145 * @param listener the listener which should no longer be notified 
    146  *  
     146 * 
    147147 * @exception IllegalArgumentException <ul> 
    148148 *    <li>ERROR_NULL_ARGUMENT when listener is null</li> 
     
    209209 */ 
    210210public void setText(String text); 
     211 
     212/++ 
     213 + DWT Extension 
     214 +/ 
     215int utf8AdjustOffset( int offset ); 
     216 
    211217} 
  • dwt/custom/StyledTextDropTargetEffect.d

    r246 r274  
    2929 
    3030static import tango.core.Exception; 
    31 import Math = tango.math.Math; 
    3231import dwt.dwthelper.utils; 
    3332 
  • dwt/custom/StyledTextEvent.d

    r212 r274  
    1919import dwt.custom.Bullet; 
    2020import dwt.custom.StyledTextContent; 
    21 import dwt.dwthelper.utils; 
    2221 
    2322/** 
  • dwt/custom/StyledTextRenderer.d

    r254 r274  
    4040 
    4141import dwt.dwthelper.Runnable; 
     42import dwt.dwthelper.utils; 
    4243 
    4344static import tango.text.Text; 
     
    4546static import tango.text.convert.Utf; 
    4647import tango.util.Convert; 
    47 import dwt.dwthelper.utils; 
    4848 
    4949/** 
     
    395395    StyledTextEvent event = styledText.getLineBackgroundData(lineOffset, line); 
    396396    if (event !is null && event.lineBackground !is null) lineBackground = event.lineBackground; 
     397 
    397398    int height = layout.getBounds().height; 
    398399    if (lineBackground !is null) {