Revision: 2369
          http://vexi.svn.sourceforge.net/vexi/?rev=2369&view=rev
Author:   clrg
Date:     2007-09-29 18:30:07 -0700 (Sat, 29 Sep 2007)

Log Message:
-----------
More improving the menu code (minor optimizations, code style clean up)

Modified Paths:
--------------
    trunk/widgets/org.vexi.widgets/src/org/vexi/lib/widget/menu.t
    trunk/widgets/org.vexi.widgets/src/org/vexi/lib/widget/menuitem.t
    trunk/widgets/org.vexi.widgets/src/org/vexi/lib/widget/submenu.t
    trunk/widgets/org.vexi.widgets/src/org/vexi/theme/win2k/menu.t
    trunk/widgets/org.vexi.widgets/src/org/vexi/theme/win2k/menuitem.t
    trunk/widgets/org.vexi.widgets/src/org/vexi/theme/win2k/submenu.t

Modified: trunk/widgets/org.vexi.widgets/src/org/vexi/lib/widget/menu.t
===================================================================
--- trunk/widgets/org.vexi.widgets/src/org/vexi/lib/widget/menu.t       
2007-09-30 00:48:22 UTC (rev 2368)
+++ trunk/widgets/org.vexi.widgets/src/org/vexi/lib/widget/menu.t       
2007-09-30 01:30:07 UTC (rev 2369)
@@ -37,7 +37,7 @@
         }
 
         /** popdown menu when a menu item is fired */
-        var childActionFunc = function(v) { popdown = true; cascade = v; }
+        var childActionWrite = function(v) { popdown = true; cascade = v; }
         
         /** th_list write trap */
         thisbox.th_list ++= function(v) {
@@ -46,12 +46,12 @@
                 if (c == null) return;
                 if (itemgroup) c.group = itemgroup;
                 else itemgroup = c.group;
-                c.action ++= childActionFunc;
+                c.action ++= childActionWrite;
                 // if locked, put has been redirected here from th_content
                 if (lockChildren) return;
                 // otherwise spoof the put back to th_content
                 lockChildren = true;
-                th_content[arguments.trapname] = c;
+                th_content[trapname] = c;
                 lockChildren = false;
             }
             
@@ -59,29 +59,29 @@
         }
         
         // assign static trap functions
-        popdown     ++= static.popdownFunc;
-        popup       ++= static.popupFunc;
-        selected    ++= static.selectedFunc;
-        Enter       ++= static.enterFunc;
-        KeyPressed  ++= static.keypressFunc;
-        KeyReleased ++= static.keyreleaseFunc;
-        Leave       ++= static.leaveFunc;
-        Press1      ++= static.pressFunc;
+        thisbox.popdown     ++= static.popdownWrite;
+        thisbox.popup       ++= static.popupWrite;
+        thisbox.selected    ++= static.selectedWrite;
+        thisbox.Enter       ++= static.enterWrite;
+        thisbox.KeyPressed  ++= static.keypressWrite;
+        thisbox.KeyReleased ++= static.keyreleaseWrite;
+        thisbox.Leave       ++= static.leaveWrite;
+        thisbox.Press1      ++= static.pressWrite;
         
     </ui:box>
     
     /** become active menu on Enter */
-    static.enterFunc = function(v) { trapee.selected = true; cascade = v; }
+    static.enterWrite = function(v) { trapee.selected = true; cascade = v; }
     
     /** deselect (become inactive) if not popped */
-    static.leaveFunc = function(v) {
+    static.leaveWrite = function(v) {
         var t = trapee;
         if (!t.popped and t.selected) t.selected = false;
         cascade = v;
     }
     
     /** menu navigation via keyboard */
-    static.keypressFunc = function(v) {
+    static.keypressWrite = function(v) {
         var t = trapee;
         var g = t.itemgroup;
         var s = g.selected;
@@ -104,14 +104,14 @@
     }
     
     /** pass key-release on as well */
-    static.keyreleaseFunc = function(v) {
+    static.keyreleaseWrite = function(v) {
         var g = trapee.itemgroup;
         if (g and g.selected) g.selected.KeyReleased = v;
         cascade = v;
     }
     
     /** open/close on mouse press */
-    static.pressFunc = function(v) {
+    static.pressWrite = function(v) {
         var t = trapee;
         if (t.enabled) {
             if (t.popped) t.popdown = true;
@@ -121,13 +121,13 @@
     }
     
     /** grab key events on popup */
-    static.popupFunc = function(v) {
+    static.popupWrite = function(v) {
         // FIXME: surface._KeyPressed ++=
         cascade = v;
     }
     
     /** popdown submenus as well */
-    static.popdownFunc = function(v) {
+    static.popdownWrite = function(v) {
         var g = trapee.itemgroup;
         if (g and g.selected) g.selected.selected = false;
         // FIXME: surface._KeyPressed --=
@@ -135,8 +135,7 @@
     }
     
     /** selected write trap */
-    static.selectedFunc = function(v)
-    {        
+    static.selectedWrite = function(v) {        
         cascade = v;
         // reduce lookups
         var t = trapee;
@@ -148,6 +147,6 @@
     }
     
     /** prevent Press events from reaching surface */
-    static.popboxPressFunc = function(v) { return true; }
+    static.popboxPressWrite = function(v) { return true; }
     
 </vexi>

Modified: trunk/widgets/org.vexi.widgets/src/org/vexi/lib/widget/menuitem.t
===================================================================
--- trunk/widgets/org.vexi.widgets/src/org/vexi/lib/widget/menuitem.t   
2007-09-30 00:48:22 UTC (rev 2368)
+++ trunk/widgets/org.vexi.widgets/src/org/vexi/lib/widget/menuitem.t   
2007-09-30 01:30:07 UTC (rev 2369)
@@ -13,17 +13,12 @@
         thisbox.selected;
         thisbox.showmnemonic = true;
         
-        Enter ++= function(v)
-        {
-            selected = true;
-            cascade = v;
-        }
+        thisbox.Enter ++= static.enterWrite;
+        thisbox.Leave ++= static.leaveWrite;
         
-        Leave ++= function(v)
-        {
-            selected = false;
-            cascade = v;
-        }
-        
     </ui:box>
+    
+    static.enterWrite = function(v) { trapee.selected = true; cascade = v; }
+    static.leaveWrite = function(v) { trapee.selected = false; cascade = v; }
+    
 </vexi>

Modified: trunk/widgets/org.vexi.widgets/src/org/vexi/lib/widget/submenu.t
===================================================================
--- trunk/widgets/org.vexi.widgets/src/org/vexi/lib/widget/submenu.t    
2007-09-30 00:48:22 UTC (rev 2368)
+++ trunk/widgets/org.vexi.widgets/src/org/vexi/lib/widget/submenu.t    
2007-09-30 01:30:07 UTC (rev 2369)
@@ -1,12 +1,13 @@
 <!-- Copyright 2007 - see COPYING for details [LGPL] -->
 
-<vexi xmlns="org.vexi.lib.role" xmlns:ui="vexi://ui" xmlns:meta="vexi://meta" 
xmlns:menu="org.vexi.lib.widget.menu">
+<vexi xmlns:ui="vexi://ui" xmlns:meta="vexi://meta"
+    xmlns="org.vexi.lib.widget" xmlns:role="org.vexi.lib.role">
     <meta:doc>
         <author>Charles Goodwin</author>
     </meta:doc>
     
-    <popupable />
-    <selectable />
+    <role:popupable />
+    <role:selectable />
     <ui:box>
         
         thisbox.action = null;
@@ -19,10 +20,8 @@
         var lockChildren = false;
         
         /** th_content write trap */
-        th_content ++= function(v)
-        {
-            v.Children ++= function(c)
-            {
+        thisbox.th_content ++= function(v) {
+            v.Children ++= function(c) {
                 // for separators
                 c.vshrink = true;
                 // if locked, spoof put from th_list is in action
@@ -35,34 +34,29 @@
                 return;
             }
             
-            v.Children ++= function()
-            {
-                return th_list[arguments.trapname];
-            }
+            v.Children ++= function() { return th_list[trapname]; }
             
             cascade = v;
         }
         
         /** popdown menu when a menu item is fired */
-        var childActionFunc = function(v) { cascade = v; popdown = true; }
+        var childActionWrite = function(v) { cascade = v; popdown = true; }
         
         /** set up submenu item list */
-        th_list ++= function(v)
-        {
-            v.Children ++= function(c)
-            {
+        thisbox.th_list ++= function(v) {
+            v.Children ++= function(c) {
                 if (c == null) {
                     // FIXME: deal with removal of children
                 } else {
                     if (itemgroup) c.group = itemgroup;
                     else itemgroup = c.group;
                     c.level = level+1;
-                    c.action ++= childActionFunc;
+                    c.action ++= childActionWrite;
                     // if locked, put has been redirected here from th_content
                     if (lockChildren) { cascade = c; return; }
                     // otherwise spoof the put back to th_content
                     lockChildren = true;
-                    th_content[arguments.trapname] = c;
+                    th_content[trapname] = c;
                     lockChildren = false;
                 }
                 cascade = c;
@@ -72,56 +66,60 @@
         }
         
         // assign static trap functions
-        level       ++= static.levelFunc;
-        popdown     ++= static.popdownFunc;
-        selected    ++= static.selectFunc;
-        th_popbox   ++= static.popboxFunc;
-        Enter       ++= menu..enterFunc;
-        KeyPressed  ++= static.keypressFunc;
-        KeyReleased ++= menu..keyreleaseFunc;
+        thisbox.level       ++= static.levelWrite;
+        thisbox.popdown     ++= static.popdownWrite;
+        thisbox.selected    ++= static.selectWrite;
+        thisbox.th_popbox   ++= static.popboxWrite;
+        thisbox.Enter       ++= .menu..enterWrite;
+        thisbox.KeyPressed  ++= static.keypressWrite;
+        thisbox.KeyReleased ++= .menu..keyreleaseWrite;
         
     </ui:box>
     
     /** set popgroup to appropriate sublevel */
-    static.levelFunc = function(v)
-    {
-        trapee.th_popbox.popgroup = "sublevel" + v;
-        for (var i=0; trapee.th_list.numchildren > i; i++)
-            trapee.th_list[i].level = v+1;
+    static.levelWrite = function(v) {
+        var t = trapee;
+        var l = t.th_list;
+        var n = l.numchildren;
+        t.th_popbox.popgroup = "sublevel" + v;
+        for (var i=0; n>i; i++) l[i].level = v+1;
         cascade = v;
     }
     
     /** navigate submenu on keypress */
-    static.keypressFunc = function(v)
-    {
+    static.keypressWrite = function(v) {
+        var t = trapee;
+        var g = g;
         if (v=="up" or v=="down") cascade = v;
-        else if (trapee.itemgroup and trapee.itemgroup.selected)
-        {
+        else if (g and g.selected) {
             if (v == "left")
             {
-                if (trapee.itemgroup.selected.popped) 
trapee.itemgroup.selected.KeyPressed = v;
-                else trapee.popdown = true;
+                if (g.selected.popped) g.selected.KeyPressed = v;
+                else t.popdown = true;
             }
             else if (v == "right")
             {
-                if (!trapee.popped) trapee.popup = true;
-                else trapee.itemgroup.selected.KeyPressed = v;
+                if (!t.popped) t.popup = true;
+                else g.selected.KeyPressed = v;
             }
-            else trapee.itemgroup.selected.KeyPressed = v;
+            else g.selected.KeyPressed = v;
             return;
         }
+        cascade = v;
     }
     
     /** deselect selected submenu item on popdown */
-    static.popdownFunc = function(v)
+    static.popdownWrite = function(v)
     {
         cascade = v;
-        if (trapee.itemgroup and trapee.itemgroup.selected) 
trapee.itemgroup.selected.selected = false;
-        if (trapee.selected) trapee.action = true;
+        var t = trapee;
+        var g = g;
+        if (g and g.selected) g.selected.selected = false;
+        if (t.selected) t.action = true;
     }
     
     /** popup/down when selected/unselected */
-    static.selectFunc = function(v)
+    static.selectWrite = function(v)
     {
         cascade = v;
         if (v) trapee.popup = true;
@@ -129,11 +127,11 @@
     }
     
     /** set up popbox */
-    static.popboxFunc = function(v)
+    static.popboxWrite = function(v)
     {
         cascade = v;
         v.popgroup = "sublevel" + trapee.level;
-        v.Press1 ++= vexi..org.vexi.lib.widget.menu..popboxPressFunc;
+        v.Press1 ++= .menu..popboxPressWrite;
     }
     
 </vexi>

Modified: trunk/widgets/org.vexi.widgets/src/org/vexi/theme/win2k/menu.t
===================================================================
--- trunk/widgets/org.vexi.widgets/src/org/vexi/theme/win2k/menu.t      
2007-09-30 00:48:22 UTC (rev 2368)
+++ trunk/widgets/org.vexi.widgets/src/org/vexi/theme/win2k/menu.t      
2007-09-30 01:30:07 UTC (rev 2369)
@@ -37,9 +37,10 @@
     static.popupWrite = function(v)
     {
         var t = trapee;
+        var d = t.surface.distanceto(t);
         t.form = "thindown";
-        t.th_popbox.surface_x = t.surface.distanceto(t).x;
-        t.th_popbox.surface_y = t.surface.distanceto(t).y + t.height;
+        t.th_popbox.surface_x = d.x;
+        t.th_popbox.surface_y = d.y + t.height;
         cascade = v;
     }
     

Modified: trunk/widgets/org.vexi.widgets/src/org/vexi/theme/win2k/menuitem.t
===================================================================
--- trunk/widgets/org.vexi.widgets/src/org/vexi/theme/win2k/menuitem.t  
2007-09-30 00:48:22 UTC (rev 2368)
+++ trunk/widgets/org.vexi.widgets/src/org/vexi/theme/win2k/menuitem.t  
2007-09-30 01:30:07 UTC (rev 2369)
@@ -34,17 +34,18 @@
     static.selectedFunc = function(v)
     {
         cascade = v;
-        if (trapee.enabled)
+        var t = trapee;
+        if (t.enabled)
         {
-            if (trapee.selected)
+            if (t.selected)
             {
-                trapee.fill = "#0a246a";
-                trapee.th_content.textcolor = "white";
+                t.fill = "#0a246a";
+                t.th_content.textcolor = "white";
             }
             else
             {
-                trapee.fill = null;
-                trapee.th_content.textcolor = "black";
+                t.fill = null;
+                t.th_content.textcolor = "black";
             }
         }
     }

Modified: trunk/widgets/org.vexi.widgets/src/org/vexi/theme/win2k/submenu.t
===================================================================
--- trunk/widgets/org.vexi.widgets/src/org/vexi/theme/win2k/submenu.t   
2007-09-30 00:48:22 UTC (rev 2368)
+++ trunk/widgets/org.vexi.widgets/src/org/vexi/theme/win2k/submenu.t   
2007-09-30 01:30:07 UTC (rev 2369)
@@ -1,6 +1,7 @@
 <!-- Copyright 2007 - see COPYING for details [LGPL] -->
 
-<vexi xmlns:ui="vexi://ui" xmlns:meta="vexi://meta" 
xmlns="org.vexi.theme.win2k" xmlns:lib="org.vexi.lib.widget">
+<vexi xmlns:ui="vexi://ui" xmlns:meta="vexi://meta"
+    xmlns:lib="org.vexi.lib.widget" xmlns="org.vexi.theme.win2k">
     <meta:doc>
         <author>Charles Goodwin</author>
     </meta:doc>
@@ -20,40 +21,37 @@
         thisbox.th_list   = $content;
         thisbox.th_popbox = $popbox;
         
-        thisbox.popup      ++= static.popupFunc;
-        thisbox.selected   ++= static.selectFunc;
-        thisbox.th_content ++= static.contentFunc;
+        thisbox.popup      ++= static.popupWrite;
+        thisbox.selected   ++= static.selectWrite;
+        thisbox.th_content ++= static.contentWrite;
         
     </ui:box>
     
-    static.contentFunc = function(v)
-    {
+    static.contentWrite = function(v) {
         v.align = "left";
         cascade = v;
     }
     
-    static.popupFunc = function(v)
-    {
-        trapee.th_popbox.surface_x = trapee.surface.distanceto(trapee).x + 
trapee.width;
-        trapee.th_popbox.surface_y = trapee.surface.distanceto(trapee).y - 2;
+    static.popupWrite = function(v) {
+        var t = trapee;
+        var d = t.surface.distanceto(t);
+        t.th_popbox.surface_x = d.x + t.width;
+        t.th_popbox.surface_y = d.y - 2;
         cascade = v;
     }
     
-    static.selectFunc = function(v)
-    {
+    static.selectWrite = function(v) {
         cascade = v;
-        if (trapee.selected)
-        {
-            trapee.fill = "#0a246a";
-            trapee.th_content.textcolor = "white";
-            trapee.th_arrow.fill = 
vexi..org.vexi.theme.win2k.image.arrowright_white;
+        var t = trapee;
+        if (t.selected) {
+            t.fill = "#0a246a";
+            t.th_content.textcolor = "white";
+            t.th_arrow.fill = .image.arrowright_white;
+        } else {
+            t.fill = null;
+            t.th_content.textcolor = "black";
+            t.th_arrow.fill = .image.arrowright;
         }
-        else
-        {
-            trapee.fill = null;
-            trapee.th_content.textcolor = "black";
-            trapee.th_arrow.fill = vexi..org.vexi.theme.win2k.image.arrowright;
-        }
     }
     
 </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: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to