- int i=0; while(i<font().length() && !Character.isDigit(font().charAt(i))) i++;
-
- if (font().lastIndexOf('d') > i) {
- for(int j = pos(0) + pad(0); j < pos(0) + pad(0) + textdim(0); j += 2)
- buf.fillRect(j, pos(1) + pad(1) + (xwf == null ? Platform.getMaxAscent(font()) : xwf.getMaxAscent()) + 2,
- j + 1, pos(1) + pad(1) + (xwf == null ? Platform.getMaxAscent(font()) : xwf.getMaxAscent()) + 2 + 1,
- textcolor);
-
- } else if (font().lastIndexOf('u') > i) {
- buf.fillRect(pos(0) + pad(0),
- pos(1) + pad(1) + (xwf == null ? Platform.getMaxAscent(font()) : xwf.getMaxAscent()) + 2,
- pos(0) + pad(0) + textdim(0),
- pos(1) + pad(1) + (xwf == null ? Platform.getMaxAscent(font()) : xwf.getMaxAscent()) + 2 + 1,
- textcolor);
- }
-
- }
-
-
- // Methods to implement org.mozilla.javascript.Scriptable //////////////////////////////////////
-
- /** Returns the i_th child */
- public Object get(int i, Scriptable start) {
- if (redirect == null) return null;
- if (redirect != this) return redirect.get(i, start);
- return i >= numChildren() ? null : getChild(i);
- }
-
- /**
- * Inserts value as child i; calls remove() if necessary.
- * This method handles "reinserting" one of your children properly.
- * INVARIANT: after completion, getChild(min(i, numChildren())) == newnode
- * WARNING: O(n) runtime, unless i == numChildren()
- */
- public void put(int i, Scriptable start, Object value) {
-
- if (value != null && !(value instanceof Box)) {
- if (Log.on) Log.log(this, "attempt to set a numerical property on a box to anything other than a box at " +
- Context.enter().interpreterSourceFile + ":" + Context.enter().interpreterLine);
-
- } else if (redirect == null) {
- if (Log.on) Log.log(this, "attempt to add/remove children to/from a node with a null redirect at " +
- Context.enter().interpreterSourceFile + ":" + Context.enter().interpreterLine);
-
- } else if (redirect != this) {
- Box b = value == null ? (Box)redirect.get(i, null) : (Box)value;
- redirect.put(i, null, value);
- put("0", null, b);
-
- } else if (value == null) {
- if (i >= 0 && i < numChildren()) {
- Box b = getChild(i);
- b.remove();
- put("0", null, b);
- }
-
- } else if (value instanceof RootProxy) {
- if (Log.on) Log.log(this, "attempt to reparent a box via its proxy object at " +
- Context.enter().interpreterSourceFile + ":" + Context.enter().interpreterLine);
-
- } else {
- Box newnode = (Box)value;
-
- // check if box being moved is currently target of a redirect
- for(Box cur = newnode.getParent(); cur != null; cur = cur.getParent())
- if (cur.redirect == newnode) {
- if (Log.on) Log.log(this, "attempt to move a box that is the target of a redirect at "+
- Context.enter().interpreterSourceFile + ":" + Context.enter().interpreterLine);
- return;
- }
-
- // check for recursive ancestor violation
- for(Box cur = this; cur != null; cur = cur.getParent())
- if (cur == newnode) {
- if (Log.on) Log.log(this, "attempt to make a node a parent of its own ancestor at " +
- Context.enter().interpreterSourceFile + ":" + Context.enter().interpreterLine);
- return;
- }
-
- if (numKids > 15 && children == null) convert_to_array();
- newnode.remove();
- newnode.parent = this;
-
- if (children == null) {
- if (firstKid == null) {
- firstKid = newnode;
- newnode.prevSibling = newnode;
- newnode.nextSibling = newnode;
- } else if (i >= numKids) {
- newnode.prevSibling = firstKid.prevSibling;
- newnode.nextSibling = firstKid;
- firstKid.prevSibling.nextSibling = newnode;
- firstKid.prevSibling = newnode;
- } else {
- Box cur = firstKid;
- for(int j=0; j<i; j++) cur = cur.nextSibling;
- newnode.prevSibling = cur.prevSibling;
- newnode.nextSibling = cur;
- cur.prevSibling.nextSibling = newnode;
- cur.prevSibling = newnode;
- if (i == 0) firstKid = newnode;
- }
- numKids++;
-
- } else {
- if (i >= children.size()) {
- newnode.indexInParent = children.size();
- children.addElement(newnode);
- } else {
- children.insertElementAt(newnode, i);
- for(int j=i; j<children.size(); j++)
- getChild(j).indexInParent = j;
- }
- }
- newnode.setSurface(surface);
-
- // need both of these in case child was already uncalc'ed
- newnode.mark_for_prerender();
- mark_for_prerender();
-
- newnode.dirty();
- sync_cmin_to_children();
-
- // note that JavaScript box[0] will invoke put(int i), not put(String s)
- put("0", null, newnode);
- }
- }
-
- public Object get(String name, Scriptable start) { return get(name, start, false); }
- public Object get(String name, Scriptable start, boolean ignoretraps) {
-
- if (name == null || name.equals("")) return null;
-
- // hack since Rhino needs to be able to grab these functions to create new objects
- if (name.equals("Object")) return JSObject.defaultObjects.get("Object", null);
- if (name.equals("Array")) return JSObject.defaultObjects.get("Array", null);
- if (name.equals("Function")) return JSObject.defaultObjects.get("Function", null);
- if (name.equals("TypeError")) return JSObject.defaultObjects.get("TypeError", null);
- if (name.equals("ConversionError")) return JSObject.defaultObjects.get("ConversionError", null);
-
- // See if we're reading back the function value of a trap
- if (name.charAt(0) == '_') {
- if (name.charAt(1) == '_') name = name.substring(2);
- else name = name.substring(1);
- Trap t = Trap.getTrap(this, name);
- return t == null ? null : t.f;
- }
-
- // See if we're triggering a trap
- Trap t = traps == null || ignoretraps ? null : (Trap)traps.get(name);
- if (t != null && t.isreadtrap) return t.perform(emptyobj);
-
- // Check for a special handler
- SpecialBoxProperty gph = (SpecialBoxProperty)SpecialBoxProperty.specialBoxProperties.get(name);
- if (gph != null) return gph.get(this);
-
- Object ret = super.get(name, start);
- if (name.startsWith("$") && ret == null)
- if (Log.on) Log.log(this, "WARNING: attempt to access " + name + ", but no child with id=\"" + name.substring(1) + "\" found; " +
- Context.enter().interpreterSourceFile + ":" + Context.enter().interpreterLine);
- return ret;
- }
-
- /** indicate that we don't want JSObject trying to handle these */
- public boolean has(String name, Scriptable start) {
- if (name.equals("")) return false;
- if (traps != null && traps.get(name) != null) return true;
- if (name.charAt(0) == '_') return true;
- if (SpecialBoxProperty.specialBoxProperties.get(name) != null) return true;
- if (name.equals("Function") || name.equals("Array") || name.equals("Object") ||
- name.equals("TypeError") || name.equals("ConversionError")) return true;
- return super.has(name, start);
- }
-
- public Object[] getIds() {
- Object[] ret = new Object[numChildren()];
- for(int i=0; i<ret.length; i++) ret[i] = get(i, null);
- return ret;
- }
-
- public void put(String name, Scriptable start, Object value) { put(name, start, value, false, null); }
- public void put(String name, Scriptable start, Object value, boolean ignoretraps) { put(name, start, value, ignoretraps, null); }
-
- /**
- * Scriptable.put()
- * @param ignoretraps if set, no traps will be triggered (set when 'cascade' reaches the bottom of the trap stack)
- * @param rp if this put is being performed via a root proxy, rp is the root proxy.
- */
- public void put(String name, Scriptable start, Object value, boolean ignoretraps, RootProxy rp) {
- if (name == null) return;
- if (name.startsWith("xwt_")) {
- if (Log.on) Log.log(this, "attempt to set reserved property " + name + " at " +
- Context.enter().interpreterSourceFile + ":" + Context.enter().interpreterLine);
- return;
- }
-
- if (!ignoretraps && traps != null) {
- Trap t = (Trap)traps.get(name);
- if (t != null) {
- Object[] arg = (Object[])singleObjects.remove(false);
- if (arg == null) arg = new Object[] { value };
- else arg[0] = value;
- t.perform(arg);
- arg[0] = null;
- singleObjects.append(arg);
- return;
- }
- }
-
- // don't want to really cascade down to the box on this one
- if (name.equals("0")) return;
-
- SpecialBoxProperty gph = (SpecialBoxProperty)SpecialBoxProperty.specialBoxProperties.get(name);
- if (gph != null) {
- gph.put(name, this, value);
- return;
- }
-
- if (name.charAt(0) == '_') {
- if (value != null && !(value instanceof Function)) {
- if (Log.on) Log.log(this, "attempt to put a non-function value to " + name + " at " +
- Context.enter().interpreterSourceFile + ":" + Context.enter().interpreterLine);
- } else if (name.charAt(1) == '_') {
- name = name.substring(2).intern();
- Trap t = Trap.getTrap(this, name);
- if (t != null) t.delete();
- if (value != null) Trap.addTrap(this, name, ((Function)value), true, rp);
- } else {
- name = name.substring(1).intern();
- Trap t = Trap.getTrap(this, name);
- if (t != null) t.delete();
- if (value != null) Trap.addTrap(this, name, ((Function)value), false, rp);
- }
- return;
- }
-
- if (ignoretraps) {
- // traps always cascade to the global property, not the local one
- putGlobally(name, start, value);
- } else {
- super.put(name, start, value);
- }
-
- // a bit of a hack, since titlebar is the only 'special' property stored in JSObject
- if (getParent() == null && surface != null) {
- if (name.equals("titlebar")) surface.setTitleBarText(value.toString());
- if (name.equals("icon")) {
- Picture pic = Box.getPicture(value.toString());
- if (pic != null) surface.setIcon(pic);
- else if (Log.on) Log.log(this, "unable to load icon " + value);
- }
- }