Changeset 274:62a03a4c21c8 for dwt/custom
- Timestamp:
- 08/03/08 17:40:57 (5 months ago)
- Files:
-
- dwt/custom/DefaultContent.d (modified) (4 diffs)
- dwt/custom/StyleRange.d (modified) (4 diffs)
- dwt/custom/StyledText.d (modified) (40 diffs)
- dwt/custom/StyledTextContent.d (modified) (3 diffs)
- dwt/custom/StyledTextDropTargetEffect.d (modified) (1 diff)
- dwt/custom/StyledTextEvent.d (modified) (1 diff)
- dwt/custom/StyledTextRenderer.d (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
dwt/custom/DefaultContent.d
r264 r274 22 22 import dwt.custom.StyledTextListener; 23 23 import dwt.custom.StyledText; 24 import dwt.dwthelper.utils; 24 25 25 26 static import tango.io.model.IFile; 26 27 static import tango.text.Text; 27 import dwt.dwthelper.utils;28 28 29 29 alias tango.text.Text.Text!(char) StringBuffer; … … 33 33 34 34 StyledTextListener[] textListeners; // stores text listeners for event sending 35 StringtextStore; // stores the actual text35 char[] textStore; // stores the actual text 36 36 int gapStart = -1; // the character position start of the gap 37 37 int gapEnd = -1; // the character position after the end of the gap … … 735 735 * 736 736 * @param listener the listener which should no longer be notified 737 * 737 * 738 738 * @exception IllegalArgumentException <ul> 739 739 * <li>ERROR_NULL_ARGUMENT when listener is null</li> … … 892 892 gapLine = getLineAtPhysicalOffset(gapStart); 893 893 } 894 } 894 895 /++ 896 + DWT extension 897 +/ 898 int 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 12 12 *******************************************************************************/ 13 13 module dwt.custom.StyleRange; 14 15 import dwt.dwthelper.utils; 14 16 15 17 … … 21 23 import dwt.custom.TextChangedEvent; 22 24 import dwt.custom.TextChangingEvent; 23 import dwt.dwthelper.utils;24 25 25 26 static import tango.text.Text; … … 66 67 public this() { 67 68 } 69 /++ 70 + DWT extension for clone implementation 71 +/ 72 protected this( StyleRange other ){ 73 super( other ); 74 start = other.start; 75 length = other.length; 76 fontStyle = other.fontStyle; 77 } 68 78 69 79 /** … … 74 84 * @since 3.4 75 85 */ 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 }82 86 public this(TextStyle style) { 83 87 super(style); dwt/custom/StyledText.d
r264 r274 150 150 */ 151 151 public class StyledText : Canvas { 152 153 152 alias Canvas.computeSize computeSize; 154 153 … … 627 626 int lastSegmentIndex = 0; 628 627 for (int i = 0; i < 3; i++) { 629 int segmentIndex = t ango.text.Util.locatePattern( text,StyledTextPrintOptions.SEPARATOR, lastSegmentIndex);628 int segmentIndex = text.indexOf( StyledTextPrintOptions.SEPARATOR, lastSegmentIndex); 630 629 String segment; 631 if (segmentIndex is text.length) {632 segment = text [ lastSegmentIndex .. $ ].dup;630 if (segmentIndex is -1 ) { 631 segment = text.substring(lastSegmentIndex); 633 632 printDecorationSegment(segment, i, page, header, layout); 634 633 break; 635 634 } else { 636 segment = text [ lastSegmentIndex .. segmentIndex ].dup;635 segment = text.substring(lastSegmentIndex, segmentIndex); 637 636 printDecorationSegment(segment, i, page, header, layout); 638 637 lastSegmentIndex = segmentIndex + StyledTextPrintOptions.SEPARATOR.length; … … 651 650 */ 652 651 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 ) { 655 654 int pageTagLength = StyledTextPrintOptions.PAGE_TAG.length; 656 StringBuffer buffer = new StringBuffer(segment [ 0 .. pageIndex ]);655 StringBuffer buffer = new StringBuffer(segment.substring (0, pageIndex)); 657 656 buffer.append (page); 658 buffer.append (segment [ pageIndex + pageTagLength .. $ ]);657 buffer.append (segment.substring(pageIndex + pageTagLength)); 659 658 segment = buffer.toString().dup; 660 659 } … … 706 705 } 707 706 } else { 708 printLayout.setText( to!(String)(index));707 printLayout.setText(to!(String)(index)); 709 708 } 710 709 int paintX = x - printMargin - printLayout.getBounds().width; … … 871 870 */ 872 871 void write(String string, int start, int end) { 873 wchar[] wstring = tango.text.convert.Utf.toString16( string[ start .. end ] );874 872 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 ); 878 877 if (ch > 0xFF && WriteUnicode) { 879 878 // write the sub string from the last escaped character 880 879 // to the current one. Fixes bug 21698. 881 880 if (index > start) { 882 write( tango.text.convert.Utf.toString(wstring[start .. index ]));881 write( string[start .. index ] ); 883 882 } 884 883 write("\\u"); 885 884 write( to!(String)( cast(short)ch )); 886 885 write(' '); // control word delimiter 887 start = index + 1;886 start = index + incr; 888 887 } else if (ch is '}' || ch is '{' || ch is '\\') { 889 888 // write the sub string from the last escaped character 890 889 // to the current one. Fixes bug 21698. 891 890 if (index > start) { 892 write( tango.text.convert.Utf.toString(wstring[start .. index]));891 write(string[start .. index]); 893 892 } 894 893 write('\\'); … … 900 899 // Fixes bug 21698. 901 900 if (start < end) { 902 write( tango.text.convert.Utf.toString(wstring[ start .. end]));901 write(string[ start .. end]); 903 902 } 904 903 } … … 1270 1269 int copyEnd = Math.min(lineLength, endOffset - lineOffset); 1271 1270 if (lineIndex < copyEnd) { 1272 write(line [lineIndex .. copyEnd]);1271 write(line.substring(lineIndex, copyEnd)); 1273 1272 } 1274 1273 } … … 1604 1603 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 1605 1604 * </ul> 1606 * @exception IllegalArgumentException <ul>1607 * <li>ERROR_NULL_ARGUMENT when listener is null</li>1608 * </ul>1609 1605 */ 1610 1606 public void append(String string) { 1611 1607 checkWidget(); 1612 // DWT extension: allow null string1613 //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 // } 1616 1612 int lastChar = Math.max(getCharCount(), 0); 1617 1613 replaceTextRange(lastChar, 0, string); … … 1938 1934 while (i < length) { 1939 1935 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); 1942 1937 } 1943 1938 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); 1946 1940 } 1947 1941 if (lfIndex is -1 && crIndex is -1) { // no more line breaks? 1948 1942 break; 1949 1943 } else if ((crIndex < lfIndex && crIndex !is -1) || lfIndex is -1) { 1950 convertedText.append(text [i .. crIndex]);1944 convertedText.append(text.substring(i, crIndex)); 1951 1945 if (lfIndex is crIndex + 1) { // CR/LF combination? 1952 1946 i = lfIndex + 1; … … 1955 1949 } 1956 1950 } else { // LF occurs before CR! 1957 convertedText.append(text [i .. lfIndex]);1951 convertedText.append(text.substring(i, lfIndex)); 1958 1952 i = lfIndex + 1; 1959 1953 } … … 1966 1960 // text copied thus far (because there only is one line) 1967 1961 if (i < length && (!isSingleLine() || convertedText.length() is 0)) { 1968 convertedText.append(text [i .. $]);1962 convertedText.append(text.substring(i)); 1969 1963 } 1970 1964 return convertedText.toString(); … … 2078 2072 Display display = getDisplay(); 2079 2073 if (leftCaretBitmap !is null) { 2080 if (defaultCaret !is null && leftCaretBitmap== defaultCaret.getImage()) {2074 if (defaultCaret !is null && leftCaretBitmap==/*eq*/defaultCaret.getImage()) { 2081 2075 defaultCaret.setImage(null); 2082 2076 } … … 2095 2089 2096 2090 if (rightCaretBitmap !is null) { 2097 if (defaultCaret !is null && rightCaretBitmap== defaultCaret.getImage()) {2091 if (defaultCaret !is null && rightCaretBitmap==/*eq*/defaultCaret.getImage()) { 2098 2092 defaultCaret.setImage(null); 2099 2093 } … … 2270 2264 * @param key the character typed by the user 2271 2265 */ 2272 void doContent( char key) {2266 void doContent(dchar key) { 2273 2267 Event event = new Event(); 2274 2268 event.start = selection.x; … … 2290 2284 // end of the line 2291 2285 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 ); 2295 2289 } else { 2296 event.text = [key];2290 event.text = dcharToString( key ); 2297 2291 } 2298 2292 if (event.text !is null) { … … 2601 2595 /** 2602 2596 * Returns the offset of the word at the specified offset. 2603 * If the current selection :from high index to low index2597 * If the current selection extends from high index to low index 2604 2598 * (i.e., right to left, or caret is at left border of selection on 2605 2599 * non-bidi platforms) the start offset of the word preceding the 2606 * selection is returned. If the current selection :from2600 * selection is returned. If the current selection extends from 2607 2601 * low index to high index the end offset of the word following 2608 2602 * the selection is returned. … … 3010 3004 int offsetInLine = caretOffset - lineOffset; 3011 3005 caretAlignment = OFFSET_LEADING; 3006 3012 3007 if (offsetInLine > 0) { 3013 3008 caretOffset = getClusterPrevious(caretOffset, caretLine); … … 3365 3360 } 3366 3361 /** 3367 * Returns whether the widget :double click mouse behavior.3362 * Returns whether the widget implements double click mouse behavior. 3368 3363 * 3369 3364 * @return true if double clicking a word selects the word, false if double clicks … … 3830 3825 * 3831 3826 * @return the top pixel of a given line index 3832 * 3827 * 3833 3828 * @since 3.2 3834 3829 */ … … 3857 3852 * Returns the line index for a y, relative to the client area. 3858 3853 * The line index returned is always in the range 0..lineCount - 1. 3859 * 3854 * 3860 3855 * @param y the y-coordinate pixel 3861 * 3856 * 3862 3857 * @return the line index for a given y-coordinate pixel 3863 3858 * … … 4951 4946 public void insert(String string) { 4952 4947 checkWidget(); 4953 // DWT extension: allow null string4954 //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 // } 4957 4952 Point sel = getSelectionRange(); 4958 4953 replaceTextRange(sel.x, sel.y, string); … … 5008 5003 addListener(DWT.Resize, listener); 5009 5004 addListener(DWT.Traverse, listener); 5010 ime.addListener(DWT.ImeComposition, new class () Listener {5005 ime.addListener(DWT.ImeComposition, new class() Listener { 5011 5006 public void handleEvent(Event event) { 5012 5007 switch (event.detail) { … … 5728 5723 if (++index >= length_) return string; 5729 5724 if (string[index] !is '&') { 5730 return string [0 .. index-1] ~ string[index .. length_];5725 return string.substring(0, index-1) ~ string.substring(index, length_); 5731 5726 } 5732 5727 index++; … … 5746 5741 while (index < length_ && string[index] !is '&') index++; 5747 5742 if (++index >= length_) return '\0'; 5748 if (string[index] !is '&') return Character ToLower(firstCodePoint( string[index .. $ ] ));5743 if (string[index] !is '&') return CharacterFirstToLower(string[index .. $ ] ); 5749 5744 index++; 5750 5745 } while (index < length_); … … 6272 6267 * 6273 6268 * @param listener the listener which should no longer be notified 6274 * 6269 * 6275 6270 * @exception DWTException <ul> 6276 6271 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> … … 6280 6275 * <li>ERROR_NULL_ARGUMENT when listener is null</li> 6281 6276 * </ul> 6282 * 6277 * 6283 6278 * @since 2.0 6284 6279 */ … … 6310 6305 * 6311 6306 * @param listener the listener which should no longer be notified 6312 * 6307 * 6313 6308 * @exception DWTException <ul> 6314 6309 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> … … 6328 6323 * 6329 6324 * @param listener the listener which should no longer be notified 6330 * 6325 * 6331 6326 * @exception DWTException <ul> 6332 6327 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> … … 6346 6341 * 6347 6342 * @param modifyListener the listener which should no longer be notified 6348 * 6343 * 6349 6344 * @exception DWTException <ul> 6350 6345 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> … … 6364 6359 * 6365 6360 * @param listener the listener which should no longer be notified 6366 * 6361 * 6367 6362 * @exception DWTException <ul> 6368 6363 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> … … 6405 6400 * 6406 6401 * @param verifyListener the listener which should no longer be notified 6407 * 6402 * 6408 6403 * @exception DWTException <ul> 6409 6404 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> … … 6423 6418 * 6424 6419 * @param listener the listener which should no longer be notified 6425 * 6420 * 6426 6421 * @exception DWTException <ul> 6427 6422 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> … … 6440 6435 * 6441 6436 * @param listener the listener which should no longer be notified 6442 * 6437 * 6443 6438 * @exception DWTException <ul> 6444 6439 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> … … 6498 6493 checkWidget(); 6499 6494 if (isListening(LineGetStyle)) return; 6500 // DWT extension: allow null array6495 // DWT extension: allow null for zero length string 6501 6496 //if (ranges is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 6502 6497 setStyleRanges(start, length, null, ranges, false); … … 6536 6531 public void replaceTextRange(int start, int length, String text) { 6537 6532 checkWidget(); 6538 // DWT extension: allow null string6539 //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 // } 6542 6537 int contentLength = getCharCount(); 6543 6538 int end = start + length; … … 7829 7824 void setSelection(int start, int length, bool sendEvent) { 7830 7825 int end = start + length; 7826 start = content.utf8AdjustOffset(start); 7827 end = content.utf8AdjustOffset(end); 7831 7828 if (start > end) { 7832 7829 int temp = end; … … 7952 7949 * </ul> 7953 7950 * @exception IllegalArgumentException <ul> 7951 * <li>ERROR_NULL_ARGUMENT when an element in the styles array is null</li> 7954 7952 * <li>ERROR_INVALID_RANGE when the number of ranges and style do not match (ranges.length * 2 is styles.length)</li> 7955 7953 * <li>ERROR_INVALID_RANGE when a range is outside the valid range (> getCharCount() or less than zero)</li> … … 7993 7991 * </ul> 7994 7992 * @exception IllegalArgumentException <ul> 7993 * <li>ERROR_NULL_ARGUMENT when an element in the styles array is null</li> 7995 7994 * <li>ERROR_INVALID_RANGE when the number of ranges and style do not match (ranges.length * 2 is styles.length)</li> 7996 7995 * <li>ERROR_INVALID_RANGE when a range is outside the valid range (> getCharCount() or less than zero)</li> … … 8128 8127 checkWidget(); 8129 8128 if (isListening(LineGetStyle)) return; 8130 // DWT extension: allow null array8129 // DWT extension: allow null for zero length string 8131 8130 //if (ranges is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 8132 8131 setStyleRanges(0, 0, null, ranges, true); … … 8170 8169 public void setText(String text) { 8171 8170 checkWidget(); 8172 // DWT extension: allow null string8173 //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 // } 8176 8175 Event event = new Event(); 8177 8176 event.start = 0; dwt/custom/StyledTextContent.d
r246 r274 13 13 module dwt.custom.StyledTextContent; 14 14 15 import dwt.dwthelper.utils; 16 15 17 import dwt.custom.TextChangeListener; 16 import dwt.dwthelper.utils;17 18 18 /** 19 19 * Clients may implement the StyledTextContent interface to provide a … … 144 144 * 145 145 * @param listener the listener which should no longer be notified 146 * 146 * 147 147 * @exception IllegalArgumentException <ul> 148 148 * <li>ERROR_NULL_ARGUMENT when listener is null</li> … … 209 209 */ 210 210 public void setText(String text); 211 212 /++ 213 + DWT Extension 214 +/ 215 int utf8AdjustOffset( int offset ); 216 211 217 } dwt/custom/StyledTextDropTargetEffect.d
r246 r274 29 29 30 30 static import tango.core.Exception; 31 import Math = tango.math.Math;32 31 import dwt.dwthelper.utils; 33 32 dwt/custom/StyledTextEvent.d
r212 r274 19 19 import dwt.custom.Bullet; 20 20 import dwt.custom.StyledTextContent; 21 import dwt.dwthelper.utils;22 21 23 22 /** dwt/custom/StyledTextRenderer.d
r254 r274 40 40 41 41 import dwt.dwthelper.Runnable; 42 import dwt.dwthelper.utils; 42 43 43 44 static import tango.text.Text; … … 45 46 static import tango.text.convert.Utf; 46 47 import tango.util.Convert; 47 import dwt.dwthelper.utils;48 48 49 49 /** … … 395 395 StyledTextEvent event = styledText.getLineBackgroundData(lineOffset, line); 396 396 if (event !is null && event.lineBackground !is null) lineBackground = event.lineBackground; 397 397 398 int height = layout.getBounds().height; 398 399 if (lineBackground !is null) {
