Revision: 4594 http://sourceforge.net/p/vexi/code/4594 Author: clrg Date: 2013-11-21 16:22:02 +0000 (Thu, 21 Nov 2013) Log Message: ----------- Padding/Margin stored on Box (no layout yet)
Modified Paths: -------------- branches/vexi4c/org.vexi-core.main/src/main/jpp/org/vexi/core/Box.jpp Added Paths: ----------- branches/vexi4c/org.vexi-core.main/src/main/java/org/vexi/core/Insets.java Added: branches/vexi4c/org.vexi-core.main/src/main/java/org/vexi/core/Insets.java =================================================================== --- branches/vexi4c/org.vexi-core.main/src/main/java/org/vexi/core/Insets.java (rev 0) +++ branches/vexi4c/org.vexi-core.main/src/main/java/org/vexi/core/Insets.java 2013-11-21 16:22:02 UTC (rev 4594) @@ -0,0 +1,80 @@ +// Copyright 2000-2013 the Contributors, as shown in the revision logs. +// Licensed under the GNU General Public License version 2 ("the License"). +// You may not use this file except in compliance with the License. + +package org.vexi.core; + +import org.ibex.js.JS; +import org.ibex.js.JSExn; +import org.ibex.js.JSU; +import org.ibex.js.Constants; + +/** + * <p>Encapsulates margin/padding state and JS interaction</p> + * + * <p>TODO: support em/pt</p> + */ +class Insets { + // default empty/0 insets + final protected static Insets ZERO = new Insets(); + + int top, right, bottom, left; + + Insets() { + top = 0; right = 0; bottom = 0; left = 0; + } + Insets(int i) { + top = i; right = i; bottom = i; left = i; + } + Insets(int t, int r, int b, int l) { + top = t; right = r; bottom = b; left = l; + } + + final JS toJS() { + if (this==ZERO) return Constants.NC_0; + if ((top==right)&&(top==bottom)&&(top==left)) + return JSU.N(top); + if (top==bottom && left==right) + return JSU.S(top+" "+left); + return JSU.S(top+" "+right+" "+bottom+" "+left); + } + final JS topToJS() { return JSU.N(top); } + final JS leftToJS() { return JSU.N(left); } + final JS rightToJS() { return JSU.N(right); } + final JS bottomToJS() { return JSU.N(bottom); } + + final Insets fromJS(JS inset) throws JSExn { + try { + if (JSU.isString(inset)) { + String[] put = inset.toString().split(" "); + if (put.length==1) { + int i = Integer.parseInt(put[0]); + if (i == top) return this; + return new Insets(i); + } else if (put.length==2) { + int v = Integer.parseInt(put[0]); + int h = Integer.parseInt(put[1]); + if (v == top && h == right && v == bottom && h == left) + return this; + return new Insets(v, h, v, h); + } else if (put.length==4) { + int t = Integer.parseInt(put[0]); + int r = Integer.parseInt(put[1]); + int b = Integer.parseInt(put[2]); + int l = Integer.parseInt(put[3]); + if (t == top && r == right && b == bottom && l == left) + return this; + return new Insets(t, r, b, l); + } else { + throw new JSExn("Invalid number of arguments for insets: "+put.length); + } + } else { + int i = JSU.toInt(inset); + if (i == top) return this; + return new Insets(i); + } + } catch(Exception e) { + throw new JSExn("Invalid insets value '"+inset+"'"); + } + } +} Property changes on: branches/vexi4c/org.vexi-core.main/src/main/java/org/vexi/core/Insets.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Modified: branches/vexi4c/org.vexi-core.main/src/main/jpp/org/vexi/core/Box.jpp =================================================================== --- branches/vexi4c/org.vexi-core.main/src/main/jpp/org/vexi/core/Box.jpp 2013-11-21 15:04:49 UTC (rev 4593) +++ branches/vexi4c/org.vexi-core.main/src/main/jpp/org/vexi/core/Box.jpp 2013-11-21 16:22:02 UTC (rev 4594) @@ -75,8 +75,8 @@ * <p>Herein considering the horizontal dimension, the contentwidth of a box is the maximum of:</p> * <ol> * <li>The value of the box's minwidth property</li> - * <li>The rendered width of the box's textual content</li> - * <li>The constrained width of the box's children</li> + * <li>The rendered width of the box's textual content plus any padding</li> + * <li>The constrained width of the box's children any padding</li> * </ol> * * <p>The constrained width of a box's children depends on the layout policy of the box:</p> @@ -163,7 +163,7 @@ // Treat following always as tokens - x/y are perhaps to short to do the same //#pragma tokens SC_ width Width WIDTH - //#define PUT_BOX_FIELD(NAME,VAL,CODE,FLAG) \ + //#define PUT_BOX_FIELD(NAME,VAL,CODE,FLAG) \ // if (test(FLAG)) {\ // Trap _t_ = wtrap(NAME);\ // JSExn _e_ = prePutTriggerTrapsAndCatchExceptions(_t_, NAME, VAL);\ @@ -172,6 +172,28 @@ // } else {\ // CODE;\ // } + + //#define REDIRECT_PUT(foo) \ + // if (redirect == null) {\ + // throw new JSExn("Attempt to set "+name+" on a box with a null redirect");\ + // }\ + // if (redirect != this) {\ + // redirect.putAndTriggerTraps(name, value);\ + // return;\ + // } + + //#define CHECKSET_INSET(INSET,SIDE,CODE) \ + // int m = JSU.toInt(value);\ + // if (INSET!=Insets.ZERO && m!=0) INSET = new Insets();\ + // INSET.SIDE = m;\ + // CODE;\ + + //#define CHECKSET_INSETOBJ(INSET,CODE) \ + // Insets _INSET = INSET.fromJS(value);\ + // if (INSET != _INSET) {\ + // INSET = _INSET;\ + // CODE;\ + // }\ // check and set functions //#define CHECKSET_SHORT(prop) ((short)JSU.toInt(value) != prop && (((prop = (short)JSU.toInt(value)) > -1) || true)) @@ -358,6 +380,8 @@ public int height = 0; protected int contentwidth = 0; // == min(maxwidth, max(minwidth, visual.textwidth, sum(child.contentwidth))) protected int contentheight = 0; + private Insets margin = null; + private Insets padding = null; // Instance Methods ///////////////////////////////////////////////////////////////////// @@ -2208,6 +2232,17 @@ case "contentwidth": return JSU.N(contentwidth); case "contentheight": return JSU.N(contentheight); + case "margin": margin.toJS(); + case "margin-top": margin.topToJS(); + case "margin-left": margin.leftToJS(); + case "margin-right": margin.rightToJS(); + case "margin-bottom": margin.bottomToJS(); + case "padding": padding.toJS(); + case "padding-top": padding.topToJS(); + case "padding-left": padding.leftToJS(); + case "padding-right": padding.rightToJS(); + case "padding-bottom": padding.bottomToJS(); + /* <p>Whether to display a box and it's contents.</p> * * <p>If this box is the root box of a window, its display property will determine whether @@ -2469,13 +2504,7 @@ throw new JSExn("Attempt to put non-null value to the 'thisbox' property"); } case "font": - if (redirect == null) { - throw new JSExn("Attempt to set "+name+" on a box with a null redirect"); - } - if (redirect != this) { - redirect.putAndTriggerTraps(name, value); - return; - } + REDIRECT_PUT(); // We do not convert to a fountain straight away as if it is a Blessing then // the fountain won't work as it will refer to the file/url without .ttf. For // the moment we handle Blessings separately for this reason. @@ -2497,13 +2526,7 @@ dirty(); } case "fontsize": - if (redirect == null) { - throw new JSExn("Attempt to set "+name+" on a box with a null redirect"); - } - if (redirect != this) { - redirect.putAndTriggerTraps(name, value); - return; - } + REDIRECT_PUT(); if (value==null) { if (!visual.resetFontsize()) { return; @@ -2518,13 +2541,7 @@ dirty(); } case "text": - if (redirect == null) { - throw new JSExn("Attempt to set "+name+" on a box with a null redirect"); - } - if (redirect != this) { - redirect.putAndTriggerTraps(name, value); - return; - } + REDIRECT_PUT(); JSString s = value == null ? null : value instanceof JSString ? (JSString)value : (JSString)JSU.S(JSU.toString(value)); if (visual.setString(s, this)) { @@ -2532,13 +2549,7 @@ dirty(); } case "textcolor": - if (redirect == null) { - throw new JSExn("Attempt to set "+name+" on a box with a null redirect"); - } - if (redirect != this) { - redirect.putAndTriggerTraps(name, value); - return; - } + REDIRECT_PUT(); try { if (value==null) { if (!visual.resetTextcolor()) { @@ -2673,22 +2684,10 @@ } } case "align": - if (redirect == null) { - throw new JSExn("Attempt to set "+name+" on a box with a null redirect"); - } - if (redirect != this) { - redirect.putAndTriggerTraps(name, value); - return; - } + REDIRECT_PUT(); setAlign(value); case "layout": - if (redirect == null) { - throw new JSExn("Attempt to set "+name+" on a box with a null redirect"); - } - if (redirect != this) { - redirect.putAndTriggerTraps(name, value); - return; - } + REDIRECT_PUT(); if (SC_place.equals(value)) { if (!test(PACK) && test(CLIP)) { return; @@ -2717,13 +2716,7 @@ throw new JSExn("Attempt to set Box property 'layout' to unsupported value '"+JSU.toString(value)+"'"); } case "orient": - if (redirect == null) { - throw new JSExn("Attempt to set "+name+" on a box with a null redirect"); - } - if (redirect != this) { - redirect.putAndTriggerTraps(name, value); - return; - } + REDIRECT_PUT(); if (SC_horizontal.equals(value)) { if (test(ORIENT)) { return; @@ -2801,7 +2794,19 @@ dirty(); } } + + case "margin": CHECKSET_INSETOBJ(margin,setParentConstrain()) + case "margin-top": CHECKSET_INSET(margin,top,setParentConstrain()) + case "margin-left": CHECKSET_INSET(margin,left,setParentConstrain()) + case "margin-right": CHECKSET_INSET(margin,right,setParentConstrain()) + case "margin-bottom": CHECKSET_INSET(margin,bottom,setParentConstrain()) + case "padding": REDIRECT_PUT(); CHECKSET_INSETOBJ(padding,setConstrain()) + case "padding-top": REDIRECT_PUT(); CHECKSET_INSET(padding,top,setConstrain()) + case "padding-left": REDIRECT_PUT(); CHECKSET_INSET(padding,left,setConstrain()) + case "padding-right": REDIRECT_PUT(); CHECKSET_INSET(padding,right,setConstrain()) + case "padding-bottom": REDIRECT_PUT(); CHECKSET_INSET(padding,bottom,setConstrain()) + // return instead of throw an exception because in some corner cases // a put is required because surface operates using a read trap, thus // boxes inheriting a 'surface' box may need to initialize themselves This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Shape the Mobile Experience: Free Subscription Software experts and developers: Be at the forefront of tech innovation. Intel(R) Software Adrenaline delivers strategic insight and game-changing conversations that shape the rapidly evolving mobile landscape. Sign up now. http://pubads.g.doubleclick.net/gampad/clk?id=63431311&iu=/4140/ostg.clktrk _______________________________________________ Vexi-svn mailing list Vexi-svn@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/vexi-svn