Revision: 3816
          http://vexi.svn.sourceforge.net/vexi/?rev=3816&view=rev
Author:   clrg
Date:     2010-03-12 14:27:35 +0000 (Fri, 12 Mar 2010)

Log Message:
-----------
Improved tree implementation

Modified Paths:
--------------
    trunk/widgets/org.vexi.widgets/src/org/vexi/theme/classic/tree.t

Modified: trunk/widgets/org.vexi.widgets/src/org/vexi/theme/classic/tree.t
===================================================================
--- trunk/widgets/org.vexi.widgets/src/org/vexi/theme/classic/tree.t    
2010-03-11 19:10:28 UTC (rev 3815)
+++ trunk/widgets/org.vexi.widgets/src/org/vexi/theme/classic/tree.t    
2010-03-12 14:27:35 UTC (rev 3816)
@@ -35,9 +35,6 @@
             </ui:box>
         </ui:box>
         
-        var content = v_content ? v_content : thisbox;
-        content.orient = "vertical";
-        
         thisbox.th_expand = $expand;
         thisbox.th_focus = $focus;
         thisbox.th_handle = $handle;
@@ -45,40 +42,75 @@
         thisbox.th_node = $node;
         thisbox.th_title = $label;
         
-        var lastc = null;
+        // last visible child in tree
+        var lastchild;
+        var lastindex = -1;
+        var checkLastChild;
+        
         var syncTrail = function(v) {
-            $vtrail.height = lastc and lastc.th_node ? (lastc.y + 
(lastc.th_node.height+1)/2) : 0;
+            $vtrail.height = lastchild?.th_node ? (lastchild.y + 
(lastchild.th_node.height+1)/2) : 0;
         }
-        var syncTrap = function(v) { cascade = v; syncTrail(); }
+        var syncTrailTrap = function(v) { cascade = v; syncTrail(); }
         
+        /* set lastchild and un-/assign traps */
+        var setLastChild = function(lastc) {
+            if (lastc != lastchild) {
+                if (lastchild) {
+                    lastchild.y --= syncTrailTrap;
+                    lastchild.display --= displayLastChild;
+                    lastchild.th_node.height --= syncTrailTrap;
+                }
+                if (lastc) {
+                    lastc.y ++= syncTrailTrap;
+                    lastc.display ++= displayLastChild;
+                    lastc.th_node.height ++= syncTrailTrap;
+                }
+                lastchild = lastc;
+                lastindex = lastchild ? v_content.indexof(lastchild) : -1;
+                syncTrail();
+            }
+            $vtrail.display = lastchild != null;
+        }
+        
+        /** find last visible node */
+        var findLastChild = function() {
+            var vc = v_content;
+            for (var i = vc.numchildren-1; i >= 0; i--) {
+                var c = vc[i];
+                if (c.display and c.th_node) {
+                    setLastChild(c);
+                    return;
+                }
+            }
+            setLastChild();
+        }
+        
+        /*var*/ displayLastChild = function(v) {
+            cascade = v;
+            if (!v) findLastChild();
+        }
+        
         thisbox.v_container ++= function(v) {
             cascade = v;
             v_textbox = $label;
             v_content.align = "left";
             v_content.orient = "vertical";
             v_content.Children ++= function(c) {
-                cascade = c;
-                // FIXME: could be much more efficient
-                var l = null;
-                for (var i = v_content.numchildren-1; i >= 0; i--) {
-                    if (v_content[i].display and v_content[i].th_node) {
-                        l = v_content[i];
-                        break;
+                if (c==null) {
+                    if (lastindex>trapname) {
+                        lastindex--;
+                    } else if (trapname==lastindex) {
+                        // need to find new last child
+                        findLastChild();
                     }
-                }
-                if (lastc != l) {
-                    if (lastc) {
-                        lastc.y --= syncTrap;
-                        lastc.th_node.height --= syncTrap;
+                } else {
+                    if (lastindex>=trapname) {
+                        lastindex++;
+                    } else if (trapname>lastindex and c.display) {
+                        setLastChild(c);
                     }
-                    if (l) {
-                        l.y ++= syncTrap;
-                        l.th_node.height ++= syncTrap;
-                    }
-                    lastc = l;
-                    syncTrail();
                 }
-                $vtrail.display = lastc != null;
+                cascade = c;
             }
         }
         


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

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to