# HG changeset patch # User Frank Benoit # Date 1217799657 -7200 # Node ID 62a03a4c21c814ab44289c17bcb314f6cd59f908 # Parent 8632408a70aa24123a5a65f7801799515d4d43fc sync StyledText with dwt-linux diff -r 8632408a70aa -r 62a03a4c21c8 dwt/custom/DefaultContent.d --- a/dwt/custom/DefaultContent.d Sun Aug 03 02:21:43 2008 +0200 +++ b/dwt/custom/DefaultContent.d Sun Aug 03 23:40:57 2008 +0200 @@ -21,10 +21,10 @@ import dwt.custom.StyledTextEvent; import dwt.custom.StyledTextListener; import dwt.custom.StyledText; +import dwt.dwthelper.utils; static import tango.io.model.IFile; static import tango.text.Text; -import dwt.dwthelper.utils; alias tango.text.Text.Text!(char) StringBuffer; @@ -32,7 +32,7 @@ private final static String LineDelimiter = tango.io.model.IFile.FileConst.NewlineString; StyledTextListener[] textListeners; // stores text listeners for event sending - String textStore; // stores the actual text + char[] textStore; // stores the actual text int gapStart = -1; // the character position start of the gap int gapEnd = -1; // the character position after the end of the gap int gapLine = -1; // the line on which the gap exists, the gap will always be associated with one line @@ -734,7 +734,7 @@ *

* * @param listener the listener which should no longer be notified - * + * * @exception IllegalArgumentException

@@ -891,4 +891,33 @@ lineCount_ -= numOldLines; gapLine = getLineAtPhysicalOffset(gapStart); } + +/++ + + DWT extension + +/ +int utf8AdjustOffset( int offset ){ + if (textStore is null) + return offset; + if (offset is 0) + return offset; + if( offset >= textStore.length ){ + return offset; + } + if (!gapExists() || (offset < gapStart)){ + while( textStore[offset] & 0xC0 is 0x80 ){ + offset--; + } + return offset; + } + int gapLength= gapEnd - gapStart; + if( offset+gapLength >= textStore.length ){ + return offset; + } + while( textStore[offset+gapLength] & 0xC0 is 0x80 ){ + offset--; + } + return offset; } + + +} diff -r 8632408a70aa -r 62a03a4c21c8 dwt/custom/StyleRange.d --- a/dwt/custom/StyleRange.d Sun Aug 03 02:21:43 2008 +0200 +++ b/dwt/custom/StyleRange.d Sun Aug 03 23:40:57 2008 +0200 @@ -12,6 +12,8 @@ *******************************************************************************/ module dwt.custom.StyleRange; +import dwt.dwthelper.utils; + import dwt.DWT; import dwt.graphics.Color; @@ -20,7 +22,6 @@ import dwt.custom.StyleRange; import dwt.custom.TextChangedEvent; import dwt.custom.TextChangingEvent; -import dwt.dwthelper.utils; static import tango.text.Text; alias tango.text.Text.Text!(char) StringBuffer; @@ -65,6 +66,15 @@ */ public this() { } +/++ + + DWT extension for clone implementation + +/ +protected this( StyleRange other ){ + super( other ); + start = other.start; + length = other.length; + fontStyle = other.fontStyle; +} /** * Create a new style range from an existing text style. @@ -73,12 +83,6 @@ * * @since 3.4 */ -public this(StyleRange style) { - this( cast(TextStyle)style); - this.start = style.start; - this.length = style.length; - this.fontStyle = style.fontStyle; -} public this(TextStyle style) { super(style); } diff -r 8632408a70aa -r 62a03a4c21c8 dwt/custom/StyledText.d --- a/dwt/custom/StyledText.d Sun Aug 03 02:21:43 2008 +0200 +++ b/dwt/custom/StyledText.d Sun Aug 03 23:40:57 2008 +0200 @@ -149,7 +149,6 @@ * @see Sample code and further information */ public class StyledText : Canvas { - alias Canvas.computeSize computeSize; static const char TAB = '\t'; @@ -626,14 +625,14 @@ if (text is null) return; int lastSegmentIndex = 0; for (int i = 0; i < 3; i++) { - int segmentIndex = tango.text.Util.locatePattern( text, StyledTextPrintOptions.SEPARATOR, lastSegmentIndex); + int segmentIndex = text.indexOf( StyledTextPrintOptions.SEPARATOR, lastSegmentIndex); String segment; - if (segmentIndex is text.length ) { - segment = text[ lastSegmentIndex .. $ ].dup; + if (segmentIndex is -1 ) { + segment = text.substring(lastSegmentIndex); printDecorationSegment(segment, i, page, header, layout); break; } else { - segment = text[ lastSegmentIndex .. segmentIndex ].dup; + segment = text.substring(lastSegmentIndex, segmentIndex); printDecorationSegment(segment, i, page, header, layout); lastSegmentIndex = segmentIndex + StyledTextPrintOptions.SEPARATOR.length; } @@ -650,12 +649,12 @@ * @param header true = print the header, false = print the footer */ void printDecorationSegment(String segment, int alignment, int page, bool header, TextLayout layout) { - int pageIndex = tango.text.Util.locatePattern( segment, StyledTextPrintOptions.PAGE_TAG ); - if (pageIndex !is segment.length ) { + int pageIndex = segment.indexOf(StyledTextPrintOptions.PAGE_TAG); + if (pageIndex !is -1 ) { int pageTagLength = StyledTextPrintOptions.PAGE_TAG.length; - StringBuffer buffer = new StringBuffer(segment[ 0 .. pageIndex ]); + StringBuffer buffer = new StringBuffer(segment.substring (0, pageIndex)); buffer.append (page); - buffer.append (segment[ pageIndex + pageTagLength .. $ ]); + buffer.append (segment.substring(pageIndex + pageTagLength)); segment = buffer.toString().dup; } if (segment.length > 0) { @@ -705,7 +704,7 @@ printLayout.setText(""); } } else { - printLayout.setText( to!(String)(index) ); + printLayout.setText(to!(String)(index)); } int paintX = x - printMargin - printLayout.getBounds().width; printLayout.draw(gc, paintX, y); @@ -870,26 +869,26 @@ * @param end end offset of segment */ void write(String string, int start, int end) { - wchar[] wstring = tango.text.convert.Utf.toString16( string[ start .. end ] ); start = 0; - end = wstring.length; - for (int index = start; index < end; index++) { - wchar ch = wstring[index]; + end = string.length; + int incr = 1; + for (int index = start; index < end; index+=incr) { + dchar ch = firstCodePoint( string[index .. $], incr ); if (ch > 0xFF && WriteUnicode) { // write the sub string from the last escaped character // to the current one. Fixes bug 21698. if (index > start) { - write(tango.text.convert.Utf.toString(wstring[start .. index ])); + write( string[start .. index ] ); } write("\\u"); write( to!(String)( cast(short)ch )); write(' '); // control word delimiter - start = index + 1; + start = index + incr; } else if (ch is '}' || ch is '{' || ch is '\\') { // write the sub string from the last escaped character // to the current one. Fixes bug 21698. if (index > start) { - write(tango.text.convert.Utf.toString(wstring[start .. index])); + write(string[start .. index]); } write('\\'); write(cast(char)ch); // ok because one of {}\ @@ -899,7 +898,7 @@ // write from the last escaped character to the end. // Fixes bug 21698. if (start < end) { - write(tango.text.convert.Utf.toString(wstring[ start .. end])); + write(string[ start .. end]); } } /** @@ -1269,7 +1268,7 @@ } int copyEnd = Math.min(lineLength, endOffset - lineOffset); if (lineIndex < copyEnd) { - write(line[lineIndex .. copyEnd]); + write(line.substring(lineIndex, copyEnd)); } } /** @@ -1603,16 +1602,13 @@ *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • * - * @exception IllegalArgumentException */ public void append(String string) { checkWidget(); - // DWT extension: allow null string - //if (string is null) { - // DWT.error(DWT.ERROR_NULL_ARGUMENT); - //} + // DWT extension: allow null for zero length string +// if (string is null) { +// DWT.error(DWT.ERROR_NULL_ARGUMENT); +// } int lastChar = Math.max(getCharCount(), 0); replaceTextRange(lastChar, 0, string); } @@ -1937,24 +1933,22 @@ String delimiter = getLineDelimiter(); while (i < length) { if (crIndex !is -1) { - crIndex = tango.text.Util.locate( text, DWT.CR, i); - if( crIndex is text.length ) crIndex = -1; + crIndex = text.indexOf (DWT.CR, i); } if (lfIndex !is -1) { - lfIndex = tango.text.Util.locate( text, DWT.LF, i); - if( lfIndex is text.length ) lfIndex = -1; + lfIndex = text.indexOf (DWT.LF, i); } if (lfIndex is -1 && crIndex is -1) { // no more line breaks? break; } else if ((crIndex < lfIndex && crIndex !is -1) || lfIndex is -1) { - convertedText.append(text[i .. crIndex]); + convertedText.append(text.substring(i, crIndex)); if (lfIndex is crIndex + 1) { // CR/LF combination? i = lfIndex + 1; } else { i = crIndex + 1; } } else { // LF occurs before CR! - convertedText.append(text[i .. lfIndex]); + convertedText.append(text.substring(i, lfIndex)); i = lfIndex + 1; } if (isSingleLine()) { @@ -1965,7 +1959,7 @@ // copy remaining text if any and if not in single line mode or no // text copied thus far (because there only is one line) if (i < length && (!isSingleLine() || convertedText.length() is 0)) { - convertedText.append(text[i .. $]); + convertedText.append(text.substring(i)); } return convertedText.toString(); } @@ -2077,7 +2071,7 @@ int caretWidth = BIDI_CARET_WIDTH; Display display = getDisplay(); if (leftCaretBitmap !is null) { - if (defaultCaret !is null && leftCaretBitmap==defaultCaret.getImage()) { + if (defaultCaret !is null && leftCaretBitmap==/*eq*/defaultCaret.getImage()) { defaultCaret.setImage(null); } leftCaretBitmap.dispose(); @@ -2094,7 +2088,7 @@ gc.dispose(); if (rightCaretBitmap !is null) { - if (defaultCaret !is null && rightCaretBitmap==defaultCaret.getImage()) { + if (defaultCaret !is null && rightCaretBitmap==/*eq*/defaultCaret.getImage()) { defaultCaret.setImage(null); } rightCaretBitmap.dispose(); @@ -2269,7 +2263,7 @@ * * @param key the character typed by the user */ -void doContent(char key) { +void doContent(dchar key) { Event event = new Event(); event.start = selection.x; event.end = selection.y; @@ -2289,11 +2283,11 @@ // replace character at caret offset if the caret is not at the // end of the line if (event.end < lineOffset + line.length) { - event.end++; - } - event.text = [key]; + event.end+=dcharToString( key ).length; + } + event.text = dcharToString( key ); } else { - event.text = [key]; + event.text = dcharToString( key ); } if (event.text !is null) { if (textLimit > 0 && content.getCharCount() - (event.end - event.start) >= textLimit) { @@ -2600,10 +2594,10 @@ } /** * Returns the offset of the word at the specified offset. - * If the current selection : from high index to low index + * If the current selection extends from high index to low index * (i.e., right to left, or caret is at left border of selection on * non-bidi platforms) the start offset of the word preceding the - * selection is returned. If the current selection : from + * selection is returned. If the current selection extends from * low index to high index the end offset of the word following * the selection is returned. * @@ -3009,6 +3003,7 @@ int lineOffset = content.getOffsetAtLine(caretLine); int offsetInLine = caretOffset - lineOffset; caretAlignment = OFFSET_LEADING; + if (offsetInLine > 0) { caretOffset = getClusterPrevious(caretOffset, caretLine); showCaret(); @@ -3364,7 +3359,7 @@ return dragDetect_; } /** - * Returns whether the widget : double click mouse behavior. + * Returns whether the widget implements double click mouse behavior. * * @return true if double clicking a word selects the word, false if double clicks * have the same effect as regular mouse clicks @@ -3829,7 +3824,7 @@ * It means this function can be used to retrieve the bottom pixel of any line. * * @return the top pixel of a given line index - * + * * @since 3.2 */ public int getLinePixel(int lineIndex) { @@ -3856,9 +3851,9 @@ /** * Returns the line index for a y, relative to the client area. * The line index returned is always in the range 0..lineCount - 1. - * + * * @param y the y-coordinate pixel - * + * * @return the line index for a given y-coordinate pixel * * @since 3.2 @@ -4950,10 +4945,10 @@ */ public void insert(String string) { checkWidget(); - // DWT extension: allow null string - //if (string is null) { - // DWT.error(DWT.ERROR_NULL_ARGUMENT); - //} + // DWT extension: allow null for zero length string +// if (string is null) { +// DWT.error(DWT.ERROR_NULL_ARGUMENT); +// } Point sel = getSelectionRange(); replaceTextRange(sel.x, sel.y, string); } @@ -5007,7 +5002,7 @@ addListener(DWT.Paint, listener); addListener(DWT.Resize, listener); addListener(DWT.Traverse, listener); - ime.addListener(DWT.ImeComposition, new class () Listener { + ime.addListener(DWT.ImeComposition, new class() Listener { public void handleEvent(Event event) { switch (event.detail) { case DWT.COMPOSITION_SELECTION: handleCompositionSelection(event); break; @@ -5727,7 +5722,7 @@ while ((index < length_) && (string[index] !is '&')) index++; if (++index >= length_) return string; if (string[index] !is '&') { - return string[0 .. index-1] ~ string[index .. length_]; + return string.substring(0, index-1) ~ string.substring(index, length_); } index++; } while (index < length_); @@ -5745,7 +5740,7 @@ do { while (index < length_ && string[index] !is '&') index++; if (++index >= length_) return '\0'; - if (string[index] !is '&') return CharacterToLower(firstCodePoint( string[index .. $ ] )); + if (string[index] !is '&') return CharacterFirstToLower(string[index .. $ ] ); index++; } while (index < length_); return '\0'; @@ -6271,7 +6266,7 @@ * Removes the specified bidirectional segment listener. * * @param listener the listener which should no longer be notified - * + * * @exception DWTException