Revision: 3719
          http://vexi.svn.sourceforge.net/vexi/?rev=3719&view=rev
Author:   clrg
Date:     2009-10-23 12:21:22 +0000 (Fri, 23 Oct 2009)

Log Message:
-----------
Fix some issues exposed by the surface.frame.Focused find by Charity
- RequestFocus not forwarded in surface.t
- surface.frame.Focused had no meaning (fixed in focusmanager)
- only enter setFocus when required (minor optimization)

Modified Paths:
--------------
    trunk/widgets/org.vexi.widgets/src/org/vexi/lib/role/focusable.t
    trunk/widgets/org.vexi.widgets/src/org/vexi/lib/role/focusmanager.t
    trunk/widgets/org.vexi.widgets/src/org/vexi/lib/role/surface.t

Modified: trunk/widgets/org.vexi.widgets/src/org/vexi/lib/role/focusable.t
===================================================================
--- trunk/widgets/org.vexi.widgets/src/org/vexi/lib/role/focusable.t    
2009-10-22 21:25:06 UTC (rev 3718)
+++ trunk/widgets/org.vexi.widgets/src/org/vexi/lib/role/focusable.t    
2009-10-23 12:21:22 UTC (rev 3719)
@@ -73,16 +73,24 @@
     
     /** write trap to set focused state */
     static.focusedWrite = function(v) {
+        // REMARK: the following sequence could be more compact
+        // but it is easier to follow in the more explicit form
         var s = trapee.surface;
         var model = s ? s.focus : null;
         if (model==null) {
             cascade = false;
-        } else {
+        } else if (v) {
             var f = trapee.focusable;
-            if (f and v) {
+            if (f) {
                 model.focusrequest = trapee;
+                cascade = model.setFocus(trapee, true);
             }
-            cascade = model.setFocus(trapee, f and v);
+        } else {
+            if (model.current == trapee) {
+                cascade = model.setFocus(trapee, false);
+            } else {
+                cascade = false;
+            }
         }
     }
     

Modified: trunk/widgets/org.vexi.widgets/src/org/vexi/lib/role/focusmanager.t
===================================================================
--- trunk/widgets/org.vexi.widgets/src/org/vexi/lib/role/focusmanager.t 
2009-10-22 21:25:06 UTC (rev 3718)
+++ trunk/widgets/org.vexi.widgets/src/org/vexi/lib/role/focusmanager.t 
2009-10-23 12:21:22 UTC (rev 3719)
@@ -20,6 +20,7 @@
         // the current focus for this surface
         var focus = null;
         var model = {};
+        var surfaceFocused = false;
         
         // the focus list for this surface
         var fvector = new .util.vector();
@@ -30,9 +31,13 @@
         surface.focus ++= function() { return model; }
         surface.focus ++= .util.common..readOnly;
         
+        /** return current frame Focused state */
+        surface.frame.Focused ++= function() { return surfaceFocused; }
+        
         /** (un)focus the focused widget according to root.Focused */
         surface.frame.Focused ++= function(v) {
             cascade = v;
+            surfaceFocused = v;
             if (focus) {
                 if (v) {
                     focus.focused = true;
@@ -45,18 +50,23 @@
         /** set or unset a focused widget */
         model.setFocus = function(v, f) {
             if (f and fvector.contains(v)) {
-                // focus
-                if (focus and focus != v) {
-                    focus.focused = false;
+                if (focus != v) {
+                    var defocus = focus;
+                    // focus
+                    focus = v;
+                    model.current = v;
+                    // REMARK: we handle defocusing after setting
+                    // the focus to avoid entering setFocus twice
+                    if (defocus) {
+                        defocus.focused = false;
+                    }
                 }
-                focus = v;
-                model.current = v;
                 return true;
             } else if (!f and focus == v) {
                 // defocus
-                if (surface.event.Focused) {
+                if (surfaceFocused) {
                     focus = null;
-                    model.focus = null;
+                    model.current = null;
                     return false;
                 }
             } else {
@@ -78,8 +88,8 @@
         
         /** drop a focus from the focus vector for this surface */
         model.dropFocus = function(v) {
-            // remove v from surface's focus model
             if (fvector.contains(v)) {
+                // remove v from surface's focus model
                 if (focus == v) {
                     var nf = model.nextFocus(v);
                     if (nf != null and nf != v) {

Modified: trunk/widgets/org.vexi.widgets/src/org/vexi/lib/role/surface.t
===================================================================
--- trunk/widgets/org.vexi.widgets/src/org/vexi/lib/role/surface.t      
2009-10-22 21:25:06 UTC (rev 3718)
+++ trunk/widgets/org.vexi.widgets/src/org/vexi/lib/role/surface.t      
2009-10-23 12:21:22 UTC (rev 3719)
@@ -73,8 +73,11 @@
         .util.redirect..addRedirect(frame, thisbox,
             "framewidth", "frameheight", "frameicon", "frametitle",
             "mouse", "distanceto", "width", "height", "x", "y",
-            "ToFront", "ToBack", "Focused", "Maximized", "Minimized");
+            "ToFront", "ToBack", "RequestFocus", "Maximized", "Minimized");
         
+        // special case Focused, forward only
+        thisbox.Focused ++= function(v) { cascade = v; frame.Focused = v; }
+        
         /*
          * THEME HANDLING
          */


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

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to