Revision: 3967
          http://vexi.svn.sourceforge.net/vexi/?rev=3967&view=rev
Author:   clrg
Date:     2010-12-01 14:52:50 +0000 (Wed, 01 Dec 2010)

Log Message:
-----------
Add 'type' to fields to limit text to alpha|numeric|alphanumeric characters

Modified Paths:
--------------
    trunk/org.vexi-vexi.widgets/src_main/org/vexi/lib/text/edit.t
    trunk/org.vexi-vexi.widgets/src_main/org/vexi/lib/text/field.t
    trunk/org.vexi-vexi.widgets/src_main/org/vexi/lib/text/word.t
    trunk/org.vexi-vexi.widgets/src_poke/visualtest/fields.t

Modified: trunk/org.vexi-vexi.widgets/src_main/org/vexi/lib/text/edit.t
===================================================================
--- trunk/org.vexi-vexi.widgets/src_main/org/vexi/lib/text/edit.t       
2010-11-30 00:23:29 UTC (rev 3966)
+++ trunk/org.vexi-vexi.widgets/src_main/org/vexi/lib/text/edit.t       
2010-12-01 14:52:50 UTC (rev 3967)
@@ -857,7 +857,7 @@
             // the index of cWord in cBlock
             cwInd = cWord ? cBlock.indexof(cWord) : null;
             if (vexi.debug) {
-                vexi.trace(v);
+                //vexi.trace(v);
             }
             
             // character insertion

Modified: trunk/org.vexi-vexi.widgets/src_main/org/vexi/lib/text/field.t
===================================================================
--- trunk/org.vexi-vexi.widgets/src_main/org/vexi/lib/text/field.t      
2010-11-30 00:23:29 UTC (rev 3966)
+++ trunk/org.vexi-vexi.widgets/src_main/org/vexi/lib/text/field.t      
2010-12-01 14:52:50 UTC (rev 3967)
@@ -15,6 +15,7 @@
         thisbox.enabled = true;
         thisbox.focused;
         thisbox.selectonfocus = true;
+        thisbox.type = null;
         thisbox.v_cursor;
         thisbox.v_edit;
         thisbox.th_view;
@@ -73,9 +74,35 @@
             // fire action
             trapee.action = true;
             trapee.value = trapee.value;
-        } else {
+        } else if (v.length>1) {
             // pass to edit
             edit.KeyPressed = v;
+        } else {
+            // alpha numeric -- 48-57 (0-9), 65-90 (A-Z), 97-122 (a-z)
+            var c = v.charCodeAt(0);
+            switch (trapee.type) {
+            case "alpha":
+                if ((c>=97 and 122>=c) or (c>=65 and 90>=c)) {
+                    // pass to edit
+                    edit.KeyPressed = v;
+                }
+                break;
+            case "alphanumeric":
+                if ((c>=97 and 122>=c) or (c>=65 and 90>=c) or (c>=48 and 
57>=c)) {
+                    // pass to edit
+                    edit.KeyPressed = v;
+                }
+                break;
+            case "numeric":
+                if (c>=48 and 57>=c) {
+                    // pass to edit
+                    edit.KeyPressed = v;
+                }
+                break;
+            default:
+                // pass to edit
+                edit.KeyPressed = v;
+            }
         }
     }
     

Modified: trunk/org.vexi-vexi.widgets/src_main/org/vexi/lib/text/word.t
===================================================================
--- trunk/org.vexi-vexi.widgets/src_main/org/vexi/lib/text/word.t       
2010-11-30 00:23:29 UTC (rev 3966)
+++ trunk/org.vexi-vexi.widgets/src_main/org/vexi/lib/text/word.t       
2010-12-01 14:52:50 UTC (rev 3967)
@@ -94,7 +94,9 @@
         for (ci=0; l>ci; ci++) {
             dx = vexi.ui.font.width(w.font, w.fontsize, t.charAt(ci));
             cx += dx;
-            if (cx - dx/2 > tx) break;
+            if (cx - dx/2 > tx) {
+                break;
+            }
         }
         // adjust return index for tab-words
         return (w.chartype != 0) ? ci : vexi.math.floor(ci/4);
@@ -132,7 +134,9 @@
         if (trapee.chartype == 0) {
             var l = cascade.length;
             var r = "";
-            for (var i=0; l>i; i+=4) r += tabchar;
+            for (var i=0; l>i; i+=4) {
+                r += tabchar;
+            }
             return r;
         }
         return cascade;
@@ -145,7 +149,10 @@
         // substitute tabs with spaces
         if (trapee.chartype == 0) {
             v = "";
-            for (var i=0; l>i; i++) v += "    ";
+            for (var i=0; l>i; i++) {
+                // FEATURE: configurable tab length
+                v += "    ";
+            }
         }
         try {
             trapee.prefwidth = vexi.ui.font.width(trapee.font, 
trapee.fontsize, v);
@@ -163,7 +170,9 @@
     static.wordcolorWrite = function(v) {
         cascade = v;
         trapee.wordcolorset = v!=null;
-        if (!trapee.highlight) trapee.textcolor = trapee.wordcolor;
+        if (!trapee.highlight) {
+            trapee.textcolor = trapee.wordcolor;
+        }
     }
     
 </vexi>

Modified: trunk/org.vexi-vexi.widgets/src_poke/visualtest/fields.t
===================================================================
--- trunk/org.vexi-vexi.widgets/src_poke/visualtest/fields.t    2010-11-30 
00:23:29 UTC (rev 3966)
+++ trunk/org.vexi-vexi.widgets/src_poke/visualtest/fields.t    2010-12-01 
14:52:50 UTC (rev 3967)
@@ -1,13 +1,26 @@
 <vexi xmlns:ui="vexi://ui" xmlns:w="vexi.widget">
     <w:surface />
     <ui:box orient="vertical">
-        <ui:box>
-            <w:textfield text="foooooo" />
+        <ui:box vshrink="true">
+            <ui:box orient="vertical">
+                <ui:box align="left" text="Normal" />
+                <ui:box align="left" text="Maxlength 3 / shrink" />
+                <ui:box align="left" text="Type alpha" />
+                <ui:box align="left" text="Type numeric" />
+                <ui:box align="left" text="Type alphanumeric" />
+                <ui:box align="left" text="Numfield" />
+                <ui:box align="left" text="Spin" />
+            </ui:box>
+            <ui:box align="left" orient="vertical">
+                <w:textfield text="foooooo" />
+                <w:textfield maxlength="3" />
+                <w:textfield type="alpha" />
+                <w:textfield type="numeric" />
+                <w:textfield type="alphanumeric" />
+                <w:numfield />
+                <w:spin />
+            </ui:box>
         </ui:box>
-        <ui:box>
-            <w:numfield />
-            <w:spin />
-        </ui:box>
         <w:textarea />
         vexi.ui.frame = thisbox;
     </ui:box>


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

------------------------------------------------------------------------------
Increase Visibility of Your 3D Game App & Earn a Chance To Win $500!
Tap into the largest installed PC base & get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to