Revision: 3349
          http://vexi.svn.sourceforge.net/vexi/?rev=3349&view=rev
Author:   clrg
Date:     2009-01-12 17:02:24 +0000 (Mon, 12 Jan 2009)

Log Message:
-----------
Iterative improvements to text widgets
- slightly more efficient code
- setting textcolor should work better now

Modified Paths:
--------------
    trunk/widgets/org.vexi.widgets/src/org/vexi/lib/text/block.t
    trunk/widgets/org.vexi.widgets/src/org/vexi/lib/text/edit.t
    trunk/widgets/org.vexi.widgets/src/org/vexi/lib/text/word.t

Modified: trunk/widgets/org.vexi.widgets/src/org/vexi/lib/text/block.t
===================================================================
--- trunk/widgets/org.vexi.widgets/src/org/vexi/lib/text/block.t        
2009-01-12 16:45:20 UTC (rev 3348)
+++ trunk/widgets/org.vexi.widgets/src/org/vexi/lib/text/block.t        
2009-01-12 17:02:24 UTC (rev 3349)
@@ -24,7 +24,7 @@
          */
         if (arguments.length) {
             var arg0 = arguments[0];
-            parent = arguments[1];
+            edit = arguments[1];
             font = arg0.font;
             fontsize = arg0.fontsize;
             multiline = arg0.multiline;
@@ -35,6 +35,7 @@
         thisbox.minheight = fontheight;
         thisbox.mWord;         // word currently occupied by mouse cursor
         thisbox.textalign;     // alignment of block text - null === default
+        thisbox.textcolorset;  // whether textcolor has been manually set
         thisbox.wordargs = [thisbox];
         thisbox.wrapwidth = 0;
         
@@ -45,25 +46,25 @@
         thisbox.activeTrap = function(v) { cascade = v; mWord = trapee; }
         
         // assign static trap functions
+        thisbox.Children  ++= static.ChildrenWrite;
         thisbox.font      ++= static.fontWrite;
         thisbox.font      ++= static.propagateOnWrite;
         thisbox.fontsize  ++= static.fontWrite;
         thisbox.fontsize  ++= static.propagateOnWrite;
         thisbox.multiline ++= static.multilineWrite;
-        thisbox.parent    ++= static.propagateOnWrite;
+        thisbox.edit      ++= static.propagateOnWrite;
         thisbox.reflow    ++= static.invokeReflow;
         thisbox.textalign ++= static.invokeReflow;
         thisbox.text      ++= static.textRead;
         thisbox.text      ++= static.textWrite;
-        thisbox.Children ++= static.ChildrenWrite;
-                
+        
     </ui:box>
     
     /** return textual content of a block from word at index */
     static.getTextFromWord = function(block, index) {
         var str = "";
-        for (var i = index+1; block.numchildren>i; i++)
-            str = str + block[i].text;
+        var n = block.numchildren;
+        for (var i = index+1; n>i; i++) str = str + block[i].text;
         return str;
     }
     
@@ -207,8 +208,8 @@
     /** propogate a property to child words */
     static.propagateOnWrite = function(v) {
         cascade = v;
-        for (var i=0; trapee.numchildren>i; i++)
-            trapee[i][trapname] = v;
+        var n = trapee.numchildren;
+        for (var i=0; n>i; i++) trapee[i][trapname] = v;
     }
     
     /** trap: set whether this is a flowing (multiline) text block or not 
(singleline) */
@@ -244,11 +245,27 @@
         }
     }
     
+    /** if block textcolor is not set, return parent edit color */
+    static.textcolorRead = function() {
+        return trapee.textcolorset ? cascade : trapee.edit.textcolor;
+    }
+    
+    /** forward textcolor write to words */
+    static.textcolorWrite = function(v) {
+        cascade = v;
+        var n = trapee.numchildren;
+        for (var i=0; n>i; i++) {
+            var w = trapee[i];
+            if (!w.wordcolorset and !w.highlight) w.textcolor = v;
+        }
+    }
+    
     /** return the textual content of a block */    
     static.textRead = function() {
         var ret = [];
         var k = 0;
-        for (var i=0; trapee.numchildren>i; i++)
+        var n = trapee.numchildren;
+        for (var i=0; n>i; i++)
             ret[k++] = trapee[i].text;
         return ret.join("");
     }

Modified: trunk/widgets/org.vexi.widgets/src/org/vexi/lib/text/edit.t
===================================================================
--- trunk/widgets/org.vexi.widgets/src/org/vexi/lib/text/edit.t 2009-01-12 
16:45:20 UTC (rev 3348)
+++ trunk/widgets/org.vexi.widgets/src/org/vexi/lib/text/edit.t 2009-01-12 
17:02:24 UTC (rev 3349)
@@ -179,6 +179,8 @@
             cascade = c;
         }
         
+        var partialHighlight = .word..partialHighlight;
+        
         /** (de)selects words between c* and a* depending on s* variables 
where:
          *  - c* represent the current cursor position 
          *  - a* represent the new cursor position
@@ -227,15 +229,15 @@
                 if (c2a) {
                     // - s2a==true, highlight
                     if (s2a) {
-                        if (sWord!=null and aWord==sWord) 
sWord.partialHighlight(sPos, aPos);
+                        if (sWord!=null and aWord==sWord) 
partialHighlight(sWord, sPos, aPos);
                         else static.highlightForwards(thisbox, cbi, cwi, 
(cWord==sWord)?sPos:null, abi, awi, aPos, s2a); 
                     
                     // - s2a==false, deselect
                     } else {
-                        if (sWord!=null and cWord==sWord) 
sWord.partialHighlight(aPos, sPos);
+                        if (sWord!=null and cWord==sWord) 
partialHighlight(sWord, aPos, sPos);
                         else {
                             static.highlightForwards(thisbox, cbi, cwi, null, 
abi, awi, aPos, s2a);
-                            if (sWord!=null and aWord==sWord) 
sWord.partialHighlight(aPos, sPos);
+                            if (sWord!=null and aWord==sWord) 
partialHighlight(sWord, aPos, sPos);
                         }
                     }
                 
@@ -243,15 +245,15 @@
                 } else {
                     // - s2a==true, deselect
                     if (s2a) {
-                        if (sWord!=null and cWord==sWord) 
sWord.partialHighlight(sPos, aPos);
+                        if (sWord!=null and cWord==sWord) 
partialHighlight(sWord, sPos, aPos);
                         else {
                             static.highlightBackwards(thisbox, cbi, cwi, null, 
abi, awi, (aWord==sWord)?sPos:aPos, !s2a);
-                            if (sWord!=null and aWord==sWord) 
sWord.partialHighlight(sPos, aPos);
+                            if (sWord!=null and aWord==sWord) 
partialHighlight(sWord, sPos, aPos);
                         }
                     
                     // - s2a==false, highlight
                     } else {
-                        if (sWord!=null and aWord==sWord) 
sWord.partialHighlight(aPos, sPos);
+                        if (sWord!=null and aWord==sWord) 
partialHighlight(sWord, aPos, sPos);
                         else static.highlightBackwards(thisbox, cbi, cwi, 
(cWord==sWord)?sPos:null, abi, awi, aPos, !s2a);
                     }
                 }
@@ -1638,6 +1640,8 @@
         return blocks;
     }
     
+    var partialHighlight = .word..partialHighlight;
+    
     /** sets the highlight going forwards from *1 to *2
      *  - p is the parent text container
      *  - b* represents the block index in p
@@ -1654,7 +1658,7 @@
             // set highlight for first word
             if (p[b1][w1]) {
                 if (c1==null) p[b1][w1].highlight = h;
-                else p[b1][w1].partialHighlight(h?c1:null, h?null:c1);
+                else partialHighlight(p[b1][w1], h?c1:null, h?null:c1);
             }
             // set highlight for rest of first block
             for (j=w1+1; p[b1].numchildren>j; j++)
@@ -1666,7 +1670,7 @@
             // set highlight for last word
             if (p[b2][w2]) {
                 if (c2==null) p[b2][w2].highlight = h;
-                else p[b2][w2].partialHighlight(h?null:c2, h?c2:null);
+                else partialHighlight(p[b2][w2], h?null:c2, h?c2:null);
             }
             // set highlight for start of last block
             for (j=0; w2>j; j++)
@@ -1677,12 +1681,12 @@
             // set highlight for first word
             if (p[b1][w1]) {
                 if (c1==null) p[b1][w1].highlight = h;
-                else p[b1][w1].partialHighlight(h?c1:null, h?null:c1);
+                else partialHighlight(p[b1][w1], h?c1:null, h?null:c1);
             }
             // set highlight for last word
             if (p[b2][w2]) {
                 if (c2==null) p[b2][w2].highlight = h;
-                else p[b2][w2].partialHighlight(h?null:c2, h?c2:null);
+                else partialHighlight(p[b2][w2], h?null:c2, h?c2:null);
             }
             // set highlight for intermediate words
             for (j=w1+1; w2>j; j++)
@@ -1693,7 +1697,7 @@
         
         // start and finish in the same word
         else if (c1 != null or c2 != null)
-            p[b1][w1].partialHighlight(h?c1:c2, h?c2:null);
+            partialHighlight(p[b1][w1], h?c1:c2, h?c2:null);
         
         // same word, character offsets not specified
         else p[b1][w1].highlight = h;
@@ -1715,7 +1719,7 @@
             // set highlight for first word
             if (p[b1][w1]) {
                 if (c1==null) p[b1][w1].highlight = h;
-                else p[b1][w1].partialHighlight(h?null:c1, h?c1:null);
+                else partialHighlight(p[b1][w1], h?null:c1, h?c1:null);
             }
             // set highlight for rest of first block
             for (j=w1-1; j>=0; j--)
@@ -1727,7 +1731,7 @@
             // set highlight for last word
             if (p[b2][w2]) {
                 if (c2==null) p[b2][w2].highlight = h;
-                else p[b2][w2].partialHighlight(h?c2:null, h?null:c2);
+                else partialHighlight(p[b2][w2], h?c2:null, h?null:c2);
             }
             // set highlight for start of last block
             for (j=p[b2].numchildren-1; j>w2; j--)
@@ -1738,11 +1742,11 @@
             // set highlight for first word
             if (p[b1][w1])
                 if (c1==null) p[b1][w1].highlight = h;
-                else p[b1][w1].partialHighlight(h?null:c1, h?c1:null);
+                else partialHighlight(p[b1][w1], h?null:c1, h?c1:null);
             // set highlight for last word
             if (p[b2][w2])
                 if (c2==null) p[b2][w2].highlight = h;
-                else p[b2][w2].partialHighlight(h?c2:null, h?null:c2);
+                else partialHighlight(p[b2][w2], h?c2:null, h?null:c2);
             // set highlight for intermediate words
             for (j=w1-1; j>w2; j--)
                 p[b1][j].highlight = h;
@@ -1752,7 +1756,7 @@
         
         // start and finish in the same word
         else if (c1 != null or c2 != null)
-            p[b1][w1].partialHighlight(h?c2:null, h?c1:c2);
+            partialHighlight(p[b1][w1], h?c2:null, h?c1:c2);
         
         // same word, character offsets not specified
         else p[b1][w1].highlight = h;

Modified: trunk/widgets/org.vexi.widgets/src/org/vexi/lib/text/word.t
===================================================================
--- trunk/widgets/org.vexi.widgets/src/org/vexi/lib/text/word.t 2009-01-12 
16:45:20 UTC (rev 3348)
+++ trunk/widgets/org.vexi.widgets/src/org/vexi/lib/text/word.t 2009-01-12 
17:02:24 UTC (rev 3349)
@@ -11,24 +11,26 @@
         </notes>
     </meta:doc>
     
-    <ui:box>
-        <ui:box id="t" shrink="true" align="bottomleft" layout="layer">
-            <ui:box id="o" align="topleft" display="false" fill="darkblue" 
hshrink="true" textcolor="white" />
-        </ui:box>
+    <ui:box hshrink="true" align="bottomleft" layout="layer">
+        <ui:box id="h" align="bottomleft" display="false" />
         
         thisbox.chartype;           // type of characters this word contains
         thisbox.highlight;          // highlight state of the word (always 
reads null)
-        thisbox.parent;             // parent block containing this word
+        thisbox.block;              // parent block containing this word
         thisbox.prefwidth = 0;      // preferred width of this word
         thisbox.valign = "bottom";  // vertical alignmnet of the word
+        thisbox.wordcolor;          // the normal color of the text
+        thisbox.wordcolorset;
+        thisbox.blockcolor = true;
         
         // initialize from parent block
         if (arguments[0]) {
             var arg0 = arguments[0];
-            parent = arg0.parent;
-            $t.font = $o.font = font = arg0.font;
-            $t.fontsize = $o.fontsize = fontsize = arg0.fontsize;
-            $t.textcolor = arg0.textcolor;
+            block = arg0;
+            textcolor = arg0.wordcolor;
+            wordcolor = arg0.wordcolor;
+            $h.font = font = arg0.font;
+            $h.fontsize = fontsize = arg0.fontsize;
             // initialize minheight
             minheight = vexi.ui.font.height(font, fontsize, "dy");
         } else throw "word arguments missing";
@@ -37,49 +39,54 @@
         highlight ++= static.highlightWrite;
         font      ++= static.fontWrite;
         fontsize  ++= static.fontWrite;
-        textcolor ++= static.textcolorWrite;
         text      ++= static.textRead;
         text      ++= static.textWrite;
         valign    ++= static.valignWrite;
+        wordcolor ++= static.wordcolorRead;
+        wordcolor ++= static.wordcolorWrite;
         
-        /** do a partial highlight
-         *  - c1 - start character
-         *  - c2 - end character
-         */
-        thisbox.partialHighlight = function(c1, c2) {
-            // just need a full highlight
-            if (c1 == null and c2 == null) {
-                highlight = true;
-                return;
-            }
-            
-            // more specific highlight required
-            if (c1 == null) c1 = 0;
-            if (c2 == null) c2 = $t.text.length;
-            // no highlight required
-            if (c1 == c2) { $o.display = false; return; }
-            if (chartype==0) { c1 *= 4; c2 *= 4; }
-            
-            $o.textcolor = parent.highlightcolor;
-            $o.fill = parent.highlightfill;
-            $t.textcolor = textcolor;
-            $t.fill = null;
-            
-            $o.text = $t.text.substring(c1, c2);
-            $o.x = vexi.ui.font.width(font, fontsize, $t.text.substring(0, 
c1));
-            
-            // foreground the background so it can contain text
-            $o.display = true;
+    </ui:box>
+    
+    /** do a partial highlight
+     *  - c1 - start character
+     *  - c2 - end character
+     */
+    static.partialHighlight = function(w, c1, c2) {
+        // just need a full highlight
+        if (c1 == null and c2 == null) {
+            w.highlight = true;
+            return;
         }
         
-    </ui:box>
+        // more specific highlight required
+        var h = w[0];
+        var t = w.text;
+        if (c1 == null) c1 = 0;
+        if (c2 == null) c2 = t.length;
+        // no highlight required
+        if (c1 == c2) { h.display = false; return; }
+        if (w.chartype==0) { c1 *= 4; c2 *= 4; }
+        
+        var edit = w.block.edit;
+        h.textcolor = edit.highlightcolor;
+        h.fill = edit.highlightfill;
+        w.textcolor = w.wordcolor;
+        w.fill = null;
+        
+        h.hshrink = true;
+        h.text = t.substring(c1, c2);
+        h.x = vexi.ui.font.width(w.font, w.fontsize, t.substring(0, c1));
+        
+        // foreground the background so it can contain text
+        h.display = true;
+    }
     
     /** returns the index of the letter closest to 'tx' in word 'w' */
     static.getIndInWord = function(w, tx) {
         var ci;
         var cx = 0;
         var dx;
-        var t = w[0].text;
+        var t = w.text;
         var l = t.length;
         for (ci=0; l>ci; ci++) {
             dx = vexi.ui.font.width(w.font, w.fontsize, t.charAt(ci));
@@ -93,23 +100,25 @@
     /** assign vertical aligment as align for inner box */
     static.valignWrite = function(v) {
         cascade = v;
-        trapee[0].align = (trapee.valign=="center"?"":v) + "left";
+        trapee.align = (trapee.valign=="center"?"":v) + "left";
+        trapee[0].align = trapee.align;
     }
     
     /** highlight write trap */
     static.highlightWrite = function(v) {
-        cascade = null;
-        trapee[0][0].display = false;
-        trapee[0].fill = v ? trapee.parent.highlightfill : null;
-        trapee[0].textcolor = v ? trapee.parent.highlightcolor : 
trapee.textcolor;
+        cascade = v;
+        var edit = trapee.block.edit;
+        trapee.fill = v ? edit.highlightfill : null;
+        trapee.textcolor = v ? edit.highlightcolor : trapee.wordcolor;
+        trapee[0].display = false;
     }
     
     /** write font information to internal text-box and highlight-box */
     static.fontWrite = function(v) {
         cascade = v;
         trapee.minheight = vexi.ui.font.height(trapee.font, trapee.fontsize, 
"dy");
-        trapee.prefwidth = vexi.ui.font.width(trapee.font, trapee.fontsize, 
trapee[0].text);
-        trapee[0][trapname] = v; trapee[0][0][trapname] = v;
+        trapee.prefwidth = vexi.ui.font.width(trapee.font, trapee.fontsize, 
trapee.text);
+        trapee[0][trapname] = v;
     }
     
     // used to create tab text returns
@@ -118,17 +127,16 @@
     /** return textual content from internal text-box */
     static.textRead = function() {
         if (trapee.chartype == 0) {
-            var l = trapee[0].text.length;
+            var l = trapee.text.length;
             var r = "";
             for (var i=0; l>i; i+=4) r += tabchar;
             return r;
         }
-        return trapee[0].text;
+        return cascade;
     }
     
     /** specialist text-write function */
     static.textWrite = function(v) {
-        cascade = null;
         // substitute tabs with spaces
         if (trapee.chartype == 0) {
             var l = v.length;
@@ -141,10 +149,18 @@
             v = "?";
             trapee.prefwidth = vexi.ui.font.width(trapee.font, 
trapee.fontsize, v);
         }
-        trapee[0].text = v ? v : "";
+        cascade = v ? v : "";
     }
     
-    /** write textcolor information to internal text-box only */
-    static.textcolorWrite = function(v) { trapee[0][trapname] = v; return; }
+    /** if wordcolor is not set, return parent block textcolor */
+    static.wordcolorRead = function() { return trapee.wordcolorset ? cascade : 
trapee.block.textcolor; }
     
+    /** handle textcolor using psuedonym wordcolor */
+    static.wordcolorWrite = function(v) {
+        cascade = v;
+        vexi.log.info("wordcolor write: "+v);
+        trapee.wordcolorset = v==null;
+        if (!trapee.highlight) trapee.textcolor = trapee.wordcolor;
+    }
+    
 </vexi>


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Vexi-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to