changeset 290:4c1340edee0d

merge
author John Reimer<terminal.node@gmail.com>
date Tue, 05 Aug 2008 18:02:58 -0700
parents a67ca5131db1 (current diff) 75cb516e281e (diff)
children b0bd1789106b
files
diffstat 7 files changed, 96 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/README	Tue Aug 05 18:01:52 2008 -0700
+++ b/README	Tue Aug 05 18:02:58 2008 -0700
@@ -2,7 +2,7 @@
 The DWT-Linux was tested successfully with this configurations:
 OS            : Linux Ubuntu 7.10
 Compiler      : DMD 1.028,1.031,1.033
-Runtime       : Tango 0.99.6
+Runtime       : Tango 0.99.7
 DSSS          : 0.75
 Lib packages  : libgtk2.0-dev,
                 libxtst-dev,
--- a/dwt/custom/StyledText.d	Tue Aug 05 18:01:52 2008 -0700
+++ b/dwt/custom/StyledText.d	Tue Aug 05 18:02:58 2008 -0700
@@ -471,7 +471,7 @@
             printerRenderer = null;
         }
     }
-    void init() {
+    void init_() {
         Rectangle trim = printer.computeTrim(0, 0, 0, 0);
         Point dpi = printer.getDPI();
 
@@ -723,7 +723,7 @@
             jobName = "Printing";
         }
         if (printer.startJob(jobName)) {
-            init();
+            init_();
             print();
             dispose();
             printer.endJob();
@@ -2240,12 +2240,13 @@
         int lineIndex = content.getLineAtOffset(caretOffset);
         int lineOffset = content.getOffsetAtLine(lineIndex);
         if (caretOffset is lineOffset) {
+            // DWT: on line start, delete line break
             lineOffset = content.getOffsetAtLine(lineIndex - 1);
             event.start = lineOffset + content.getLine(lineIndex - 1).length;
             event.end = caretOffset;
         } else {
             TextLayout layout = renderer.getTextLayout(lineIndex);
-            int start = layout.getPreviousOffset(caretOffset - lineOffset, DWT.MOVEMENT_CHAR);
+            int start = layout.getPreviousOffset(caretOffset - lineOffset, DWT.MOVEMENT_CLUSTER);
             renderer.disposeTextLayout(layout);
             event.start = start + lineOffset;
             event.end = caretOffset;
@@ -3987,7 +3988,7 @@
 int getOffsetAtPoint(int x, int y, int lineIndex) {
     TextLayout layout = renderer.getTextLayout(lineIndex);
     x += horizontalScrollOffset - leftMargin;
-    int[] trailing = new int[1];
+    int[1] trailing;
     int offsetInLine = layout.getOffset(x, y, trailing);
     caretAlignment = OFFSET_LEADING;
     if (trailing[0] !is 0) {
@@ -4909,7 +4910,9 @@
     TextLayout layout = renderer.getTextLayout(lineIndex);
     if (lineLength !is 0  && offsetInLine <= lineLength) {
         if (offsetInLine is lineLength) {
-            point = layout.getLocation(offsetInLine - 1, true);
+            // DWT: Instead of go back one byte, go back one codepoint
+            int offsetInLine_m1 = layout.getPreviousOffset(offsetInLine, DWT.MOVEMENT_CLUSTER);
+            point = layout.getLocation(offsetInLine_m1, true);
         } else {
             switch (caretAlignment) {
                 case OFFSET_LEADING:
@@ -4920,7 +4923,9 @@
                     if (offsetInLine is 0) {
                         point = layout.getLocation(offsetInLine, false);
                     } else {
-                        point = layout.getLocation(offsetInLine - 1, true);
+                        // DWT: Instead of go back one byte, go back one codepoint
+                        int offsetInLine_m1 = layout.getPreviousOffset(offsetInLine, DWT.MOVEMENT_CLUSTER);
+                        point = layout.getLocation(offsetInLine_m1, true);
                     }
                     break;
             }
@@ -5008,6 +5013,7 @@
                 case DWT.COMPOSITION_SELECTION: handleCompositionSelection(event); break;
                 case DWT.COMPOSITION_CHANGED: handleCompositionChanged(event); break;
                 case DWT.COMPOSITION_OFFSET: handleCompositionOffset(event); break;
+                default:
             }
         }
     });
@@ -8322,6 +8328,7 @@
     setCaretLocation();
     super.redraw();
 }
+// DWT: If necessary, scroll to show the location
 bool showLocation(Rectangle rect, bool scrollPage) {
     int clientAreaWidth = this.clientAreaWidth - leftMargin - rightMargin;
     int clientAreaHeight = this.clientAreaHeight - topMargin - bottomMargin;
--- a/dwt/custom/StyledTextContent.d	Tue Aug 05 18:01:52 2008 -0700
+++ b/dwt/custom/StyledTextContent.d	Tue Aug 05 18:02:58 2008 -0700
@@ -143,7 +143,7 @@
  * <p>
  *
  * @param listener the listener which should no longer be notified
- * 
+ *
  * @exception IllegalArgumentException <ul>
  *    <li>ERROR_NULL_ARGUMENT when listener is null</li>
  * </ul>
--- a/dwt/dwthelper/File.d	Tue Aug 05 18:01:52 2008 -0700
+++ b/dwt/dwthelper/File.d	Tue Aug 05 18:02:58 2008 -0700
@@ -7,6 +7,7 @@
 
 static import tango.io.model.IFile;
 static import tango.io.FilePath;
+static import tango.io.Path;
 static import tango.io.FileSystem;
 
 public class File {
@@ -26,7 +27,7 @@
     }
 
     public this ( String pathname ){
-        mFilePath = new tango.io.FilePath.FilePath( pathname );
+        mFilePath = new tango.io.FilePath.FilePath( tango.io.Path.standard( pathname ));
     }
 
     public this ( String parent, String child ){
--- a/dwt/dwthelper/utils.d	Tue Aug 05 18:01:52 2008 -0700
+++ b/dwt/dwthelper/utils.d	Tue Aug 05 18:02:58 2008 -0700
@@ -230,6 +230,8 @@
 alias Integer ValueWrapperInt;
 
 class Double : ValueWrapperT!(double) {
+    public static double MAX_VALUE = double.max;
+    public static double MIN_VALUE = double.min;
     this( double value ){
         super(value);
     }
@@ -338,9 +340,13 @@
     return res;
 }
 int indexToCodepointIndex( String str, int index ){
+    if( index < 0 ) return index;
     int i = 0;
     int res = 0;
     while( i < index ){
+        if( i >= str.length ){
+            break;
+        }
         if( str[i] < 0x80 ){
             i+=1;
         }
@@ -433,7 +439,7 @@
                 i+=4;
             }
             else{
-                Trace.formatln( "invalid utf8 characters: {:X2}", cast(ubyte[]) str );
+                Trace.formatln( "invalid utf8 characters:  {:X2}", cast(ubyte[]) str );
                 tango.text.convert.Utf.onUnicodeError( "invalid utf8 input", i );
             }
             searchRelCp--;
@@ -444,8 +450,9 @@
             do{
                 i--;
                 if( i < 0 ){
-                    Trace.formatln( "dwthelper.utils getRelativeCodePointOffset {}: str={}, startIndex={}, searchRelCp={}", __LINE__, str, startIndex, searchRelCp );
-                    tango.text.convert.Utf.onUnicodeError( "invalid utf8 input", i );
+                    return -1;
+                    //Trace.formatln( "dwthelper.utils getRelativeCodePointOffset {}: str={}, startIndex={}, searchRelCp={}", __LINE__, str, startIndex, searchRelCp );
+                    //tango.text.convert.Utf.onUnicodeError( "invalid utf8 input", i );
                 }
             } while(( str[i] & 0xC0 ) is 0x80 );
             searchRelCp++;
@@ -468,6 +475,32 @@
     }
     return offset;
 }
+int utf8OffsetIncr( String str, int offset ){
+    int res = offset +1;
+    if( str.length <= res || res <= 0 ){
+        return res;
+    }
+    int tries = 4;
+    while(( str[res] & 0xC0 ) is 0x80 ){
+        res++;
+        assert( tries-- > 0 );
+    }
+    return res;
+}
+int utf8OffsetDecr( String str, int offset ){
+    int res = offset-1;
+    if( str.length <= res || res <= 0 ){
+        return res;
+    }
+    int tries = 4;
+    while(( str[res] & 0xC0 ) is 0x80 ){
+        res--;
+        assert( tries-- > 0 );
+    }
+    Trace.formatln( "utf8OffsetDecr {}->{}", offset, res );
+    Trace.memory( str );
+    return res;
+}
 
 bool CharacterIsDefined( dchar ch ){
     return (ch in tango.text.UnicodeData.unicodeData) !is null;
@@ -969,3 +1002,4 @@
 template getImportData(String name ){
     const ImportData getImportData = ImportData( import(name), name );
 }
+
--- a/dwt/graphics/TextLayout.d	Tue Aug 05 18:01:52 2008 -0700
+++ b/dwt/graphics/TextLayout.d	Tue Aug 05 18:02:58 2008 -0700
@@ -140,7 +140,7 @@
     if (styles.length is 2 && styles[0].style is null && ascent is -1 && descent is -1 && segments is null) return;
     auto ptr = OS.pango_layout_get_text(layout);
     attrList = OS.pango_attr_list_new();
-    //PangoAttribute* attribute = new PangoAttribute();
+    PangoAttribute* attribute;
     char[] chars = null;
     int segementsLength = segmentsText.length;
     if ((ascent !is -1  || descent !is -1) && segementsLength > 0) {
@@ -156,12 +156,14 @@
             /* Note: The length in bytes of ZWS and ZWNBS are both equals to 3 */
             int offset = lineIndex * 6;
             PangoAttribute* attr = OS.pango_attr_shape_new (&rect, &rect);
-            attr.start_index = bytePos + offset;
-            attr.end_index = bytePos + offset + 3;
+            attribute = attr;
+            attribute.start_index = bytePos + offset;
+            attribute.end_index = bytePos + offset + 3;
             OS.pango_attr_list_insert(attrList, attr);
             attr = OS.pango_attr_shape_new (&rect, &rect);
-            attr.start_index = bytePos + offset + 3;
-            attr.end_index = bytePos + offset + 6;
+            attribute = attr;
+            attribute.start_index = bytePos + offset + 3;
+            attribute.end_index = bytePos + offset + 6;
             OS.pango_attr_list_insert(attrList, attr);
             int pos = bytePos;//OS.g_utf8_pointer_to_offset(ptr, ptr + bytePos);
             chars[pos + lineIndex * 6 +0 .. pos + lineIndex * 6 + 3] = STR_ZWS;
@@ -1347,28 +1349,31 @@
     }
     PangoLogAttr* attrs;
     int nAttrs;
+    // return one attr per codepoint (=char in pango)
     OS.pango_layout_get_log_attrs(layout, &attrs, &nAttrs);
     if (attrs is null) return offset + step;
-    length_ = OS.g_utf8_strlen(cont, -1);
+    length_ = dcont.length;//OS.g_utf8_strlen(cont, -1);
     offset = translateOffset(offset);
     offset = dcont.utf8AdjustOffset( offset );
-    PangoLogAttr* logAttr = new PangoLogAttr();
+
+    PangoLogAttr* logAttr;
     offset = validateOffset( dcont, offset, step);
+    // the loop is byte oriented
     while (0 < offset && offset < length_) {
-        *logAttr = attrs[ offset ];
-        if (((movement & DWT.MOVEMENT_CLUSTER) !is 0) && ( logAttr.bitfield0 & (1<<4/*is_cursor_position*/))) break;
+        logAttr = & attrs[ OS.g_utf8_pointer_to_offset( cont, cont+offset) ];
+        if (((movement & DWT.MOVEMENT_CLUSTER) !is 0) && logAttr.is_cursor_position ) break;
         if ((movement & DWT.MOVEMENT_WORD) !is 0) {
             if (forward) {
-                if (logAttr.bitfield0 & (1<<6/*is_word_end*/)) break;
+                if (logAttr.is_word_end ) break;
             } else {
-                if (logAttr.bitfield0 & (1<<5/*is_word_start*/)) break;
+                if (logAttr.is_word_start ) break;
             }
         }
         if ((movement & DWT.MOVEMENT_WORD_START) !is 0) {
-            if (logAttr.bitfield0 & (1<<5/*is_word_start*/)) break;
+            if (logAttr.is_word_start ) break;
         }
         if ((movement & DWT.MOVEMENT_WORD_END) !is 0) {
-            if (logAttr.bitfield0 & (1<<6/*is_word_end*/)) break;
+            if (logAttr.is_word_end ) break;
         }
         offset = validateOffset( dcont, offset, step);
     }
--- a/dwt/internal/c/pango.d	Tue Aug 05 18:01:52 2008 -0700
+++ b/dwt/internal/c/pango.d	Tue Aug 05 18:02:58 2008 -0700
@@ -531,6 +531,30 @@
 }
 struct _PangoLogAttr {
 uint bitfield0;
+bool is_line_break              (){ return (bitfield0 & (1<< 0)) !is 0; }
+bool is_mandatory_break         (){ return (bitfield0 & (1<< 1)) !is 0; }
+bool is_char_break              (){ return (bitfield0 & (1<< 2)) !is 0; }
+bool is_white                   (){ return (bitfield0 & (1<< 3)) !is 0; }
+bool is_cursor_position         (){ return (bitfield0 & (1<< 4)) !is 0; }
+bool is_word_start              (){ return (bitfield0 & (1<< 5)) !is 0; }
+bool is_word_end                (){ return (bitfield0 & (1<< 6)) !is 0; }
+bool is_sentence_boundary       (){ return (bitfield0 & (1<< 7)) !is 0; }
+bool is_sentence_start          (){ return (bitfield0 & (1<< 8)) !is 0; }
+bool is_sentence_end            (){ return (bitfield0 & (1<< 9)) !is 0; }
+bool backspace_deletes_character(){ return (bitfield0 & (1<<10)) !is 0; }
+bool is_expandable_space        (){ return (bitfield0 & (1<<11)) !is 0; }
+bool is_line_break              (bool v){ if(v) bitfield0 |= (1<< 0); else bitfield0 &= ~(1<< 0); return v; }
+bool is_mandatory_break         (bool v){ if(v) bitfield0 |= (1<< 1); else bitfield0 &= ~(1<< 1); return v; }
+bool is_char_break              (bool v){ if(v) bitfield0 |= (1<< 2); else bitfield0 &= ~(1<< 2); return v; }
+bool is_white                   (bool v){ if(v) bitfield0 |= (1<< 3); else bitfield0 &= ~(1<< 3); return v; }
+bool is_cursor_position         (bool v){ if(v) bitfield0 |= (1<< 4); else bitfield0 &= ~(1<< 4); return v; }
+bool is_word_start              (bool v){ if(v) bitfield0 |= (1<< 5); else bitfield0 &= ~(1<< 5); return v; }
+bool is_word_end                (bool v){ if(v) bitfield0 |= (1<< 6); else bitfield0 &= ~(1<< 6); return v; }
+bool is_sentence_boundary       (bool v){ if(v) bitfield0 |= (1<< 7); else bitfield0 &= ~(1<< 7); return v; }
+bool is_sentence_start          (bool v){ if(v) bitfield0 |= (1<< 8); else bitfield0 &= ~(1<< 8); return v; }
+bool is_sentence_end            (bool v){ if(v) bitfield0 |= (1<< 9); else bitfield0 &= ~(1<< 9); return v; }
+bool backspace_deletes_character(bool v){ if(v) bitfield0 |= (1<<10); else bitfield0 &= ~(1<<10); return v; }
+bool is_expandable_space        (bool v){ if(v) bitfield0 |= (1<<11); else bitfield0 &= ~(1<<11); return v; }
 // uint is_line_break // bits 0 .. 1
 // uint is_mandatory_break // bits 1 .. 2
 // uint is_char_break // bits 2 .. 3