comparison org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/custom/DefaultContent.d @ 120:536e43f63c81

Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661 ===D2=== * added [Try]Immutable/Const/Shared templates to work with differenses in D1/D2 instead of version statements used these templates to work with strict type storage rules of dmd-2.053 * com.ibm.icu now also compilable with D2, but not tested yet * small fixes Snippet288 - shared data is in TLS ===Phobos=== * fixed critical bugs in Phobos implemention completely incorrect segfault prone fromStringz (Linux's port ruthless killer) terrible, incorrect StringBuffer realization (StyledText killer) * fixed small bugs as well Snippet72 - misprint in the snippet * implemented missed functionality for Phobos ByteArrayOutputStream implemented (image loading available) formatting correctly works for all DWT's cases As a result, folowing snippets now works with Phobos (Snippet### - what is fixed): Snippet24, 42, 111, 115, 130, 235, 276 - bad string formatting Snippet48, 282 - crash on image loading Snippet163, 189, 211, 213, 217, 218, 222 - crash on copy/cut in StyledText Snippet244 - hang-up ===Tango=== * few changes for the latest Tango trunc-r5661 * few small performance improvments ===General=== * implMissing-s for only one version changed to implMissingInTango/InPhobos * incorrect calls to Format in toString-s fixed * fixed loading \uXXXX characters in ResourceBundle * added good UTF-8 support for StyledText, TextLayout (Win32) and friends UTF functions revised and tested. It is now in java.nonstandard.*Utf modules StyledText and TextLayout (Win32) modules revised for UTF-8 support * removed small diferences in most identical files in *.swt.* folders *.swt.internal.image, *.swt.events and *.swt.custom are identical in Win32/Linux32 now 179 of 576 (~31%) files in *.swt.* folders are fully identical * Win32: snippets now have right subsystem, pretty icons and native system style controls * small fixes in snippets Snippet44 - it's not Snippet44 Snippet212 - functions work with different images and offsets arrays Win32: Snippet282 - crash on close if the button has an image Snippet293 - setGrayed is commented and others Win32: As a result, folowing snippets now works Snippet68 - color doesn't change Snippet163, 189, 211, 213, 217, 218, 222 - UTF-8 issues (see above) Snippet193 - no tabel headers
author Denis Shelomovskij <verylonglogin.reg@gmail.com>
date Sat, 09 Jul 2011 15:50:20 +0300
parents 9f4c18c268b2
children
comparison
equal deleted inserted replaced
119:d00e8db0a568 120:536e43f63c81
9 * IBM Corporation - initial API and implementation 9 * IBM Corporation - initial API and implementation
10 * Port to the D programming language: 10 * Port to the D programming language:
11 * Frank Benoit <benoit@tionex.de> 11 * Frank Benoit <benoit@tionex.de>
12 *******************************************************************************/ 12 *******************************************************************************/
13 module org.eclipse.swt.custom.DefaultContent; 13 module org.eclipse.swt.custom.DefaultContent;
14
15 import java.lang.all;
16 14
17 import org.eclipse.swt.SWT; 15 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.SWTException; 16 import org.eclipse.swt.SWTException;
19 import org.eclipse.swt.internal.Compatibility; 17 import org.eclipse.swt.internal.Compatibility;
20 import org.eclipse.swt.widgets.TypedListener; 18 import org.eclipse.swt.widgets.TypedListener;
22 import org.eclipse.swt.custom.TextChangeListener; 20 import org.eclipse.swt.custom.TextChangeListener;
23 import org.eclipse.swt.custom.StyledTextEvent; 21 import org.eclipse.swt.custom.StyledTextEvent;
24 import org.eclipse.swt.custom.StyledTextListener; 22 import org.eclipse.swt.custom.StyledTextListener;
25 import org.eclipse.swt.custom.StyledText; 23 import org.eclipse.swt.custom.StyledText;
26 24
25 import java.lang.all;
26 import java.nonstandard.UnsafeUtf;
27
28 version(Tango){
29 static import tango.io.model.IFile;
30 } else { // Phobos
31 static import std.string;
32 }
33
34
27 class DefaultContent : StyledTextContent { 35 class DefaultContent : StyledTextContent {
28 private const static String LineDelimiter = "\r\n"; 36 version(Tango){
37 private const static String LineDelimiter = tango.io.model.IFile.FileConst.NewlineString;
38 } else { // Phobos
39 private const static String LineDelimiter = std.string.newline;
40 }
29 41
30 StyledTextListener[] textListeners; // stores text listeners for event sending 42 StyledTextListener[] textListeners; // stores text listeners for event sending
31 char[] textStore; // stores the actual text 43 char[] textStore; // stores the actual text
32 int gapStart = -1; // the character position start of the gap 44 int gapStart = -1; // the character position start of the gap
33 int gapEnd = -1; // the character position after the end of the gap 45 int gapEnd = -1; // the character position after the end of the gap
496 return textStore[ start .. start + length_]._idup(); 508 return textStore[ start .. start + length_]._idup();
497 } else { 509 } else {
498 // gap is in the specified range, strip out the gap 510 // gap is in the specified range, strip out the gap
499 StringBuffer buf = new StringBuffer(); 511 StringBuffer buf = new StringBuffer();
500 int gapLength = gapEnd - gapStart; 512 int gapLength = gapEnd - gapStart;
501 buf.append(textStore, start, gapStart - start); 513 buf.append(textStore[ start .. gapStart ] );
502 buf.append(textStore, gapEnd, length_ - gapLength - (gapStart - start)); 514 buf.append(textStore[ gapEnd .. gapEnd + length_ - gapLength - (gapStart - start) ]);
503 length_ = buf.length(); 515 length_ = buf.length;
504 while ((length_ - 1 >=0) && isDelimiter(buf.charAt(length_ - 1))) { 516 while ((length_ - 1 >=0) && isDelimiter(buf.slice[length_ - 1])) {
505 length_--; 517 length_--;
506 } 518 }
507 return buf.toString().substring(0, length_); 519 return buf.slice()[ 0 .. length_ ]._idup();
508 } 520 }
509 } 521 }
510 /** 522 /**
511 * Returns the line delimiter that should be used by the StyledText 523 * Returns the line delimiter that should be used by the StyledText
512 * widget when inserting new lines. This delimiter may be different than the 524 * widget when inserting new lines. This delimiter may be different than the
536 // gap is in the specified range, strip out the gap 548 // gap is in the specified range, strip out the gap
537 StringBuffer buffer = new StringBuffer(); 549 StringBuffer buffer = new StringBuffer();
538 int gapLength = gapEnd - gapStart; 550 int gapLength = gapEnd - gapStart;
539 buffer.append(textStore[ start .. gapStart ]); 551 buffer.append(textStore[ start .. gapStart ]);
540 buffer.append(textStore[ gapEnd .. gapEnd + length_ - gapLength - (gapStart - start) ]); 552 buffer.append(textStore[ gapEnd .. gapEnd + length_ - gapLength - (gapStart - start) ]);
541 return buffer.toString()._idup(); 553 return buffer.toString();
542 } 554 }
543 } 555 }
544 /** 556 /**
545 * Returns the physical line at the given index (i.e., with delimiters and the gap). 557 * Returns the physical line at the given index (i.e., with delimiters and the gap).
546 * <p> 558 * <p>
559 public int getLineCount(){ 571 public int getLineCount(){
560 return lineCount_; 572 return lineCount_;
561 } 573 }
562 /** 574 /**
563 * Returns the line at the given offset. 575 * Returns the line at the given offset.
576 * DWT: index can be an invalid UTF-8 index
564 * <p> 577 * <p>
565 * 578 *
566 * @param charPosition logical character offset (i.e., does not include gap) 579 * @param charPosition logical character offset (i.e., does not include gap)
567 * @return the line index 580 * @return the line index
568 * @exception IllegalArgumentException <ul> 581 * @exception IllegalArgumentException <ul>
721 return textStore[ start + gapLength .. start + gapLength + length_ ]._idup(); 734 return textStore[ start + gapLength .. start + gapLength + length_ ]._idup();
722 } 735 }
723 StringBuffer buf = new StringBuffer(); 736 StringBuffer buf = new StringBuffer();
724 buf.append(textStore[ start .. start + gapStart - start ] ); 737 buf.append(textStore[ start .. start + gapStart - start ] );
725 buf.append(textStore[ gapEnd .. gapEnd + end - gapStart ] ); 738 buf.append(textStore[ gapEnd .. gapEnd + end - gapStart ] );
726 return buf.toString()._idup(); 739 return buf.toString();
727 } 740 }
728 /** 741 /**
729 * Removes the specified <code>TextChangeListener</code>. 742 * Removes the specified <code>TextChangeListener</code>.
730 * <p> 743 * <p>
731 * 744 *
886 } 899 }
887 lineCount_ -= numOldLines; 900 lineCount_ -= numOldLines;
888 gapLine = getLineAtPhysicalOffset(gapStart); 901 gapLine = getLineAtPhysicalOffset(gapStart);
889 } 902 }
890 903
891 /++ 904
892 + SWT extension 905 }
893 +/
894 int utf8AdjustOffset( int offset ){
895 if (textStore is null)
896 return offset;
897 if (offset is 0)
898 return offset;
899 if( offset >= textStore.length ){
900 return offset;
901 }
902 if (!gapExists() || (offset < gapStart)){
903 while( (textStore[offset] & 0xC0) is 0x80 ){
904 offset--;
905 }
906 return offset;
907 }
908 int gapLength= gapEnd - gapStart;
909 if( offset+gapLength >= textStore.length ){
910 return offset;
911 }
912 while( (textStore[offset+gapLength] & 0xC0) is 0x80 ){
913 offset--;
914 }
915 return offset;
916 }
917
918
919 }