DEFAULT_FONT = f;
}
+ // FIXME update these
// box properties can not be trapped
static final String[] props = new String[] {
"fill", "stroke", "image", "tile", "fixedaspect", "text", "path", "font",
"mouseinside", "root", "thisbox", "indexof"
};
+ // FIXME update these
// events can have write traps, but not read traps
static final String[] events = new String[] {
"Press1", "Press2", "Press3",
"DoubleClick1", "DoubleClick2", "DoubleClick3",
"Enter", "Leave", "Move",
"KeyPressed", "KeyReleased", "PosChange", "SizeChange",
-
"childadded", "childremoved",
-
"Focused", "Maximized", "Minimized", "Close",
"icon", "titlebar", "toback", "tofront"
};
static final int ALIGNS = 0x0000f000;
static final int CURSOR = 0x00010000; // if true, this box has a cursor in the cursor hash; FEATURE: GC issues?
static final int NOCLIP = 0x00020000;
+ static final int STOP_UPWARD_PROPAGATION = 0x00040000;
// Instance Data //////////////////////////////////////////////////////////////////////
Box parent = null;
Box redirect = this;
- int flags = VISIBLE | PACKED | REPACK | REFLOW | RESIZE | FIXED /* ROWS */;
+ int flags = VISIBLE | PACKED | REPACK | REFLOW | RESIZE | FIXED /* ROWS */ | STOP_UPWARD_PROPAGATION;
private String text = null;
private Font font = DEFAULT_FONT;
}
}
- /** update MOUSEINSIDE, check for Enter/Leave/Move */
- void Move(int oldmousex, int oldmousey, int mousex, int mousey) { Move(oldmousex, oldmousey, mousex, mousey, false); }
- void Move(int oldmousex, int oldmousey, int mousex, int mousey, boolean forceleave) {
- boolean wasinside = test(MOUSEINSIDE);
- boolean isinside = test(VISIBLE) && inside(mousex, mousey) && !forceleave;
- if (isinside) set(MOUSEINSIDE); else clear(MOUSEINSIDE);
- if (!wasinside && !isinside) return;
-
- if (isinside && test(CURSOR)) Surface.fromBox(getRoot()).cursor = (String)boxToCursor.get(this);
- if (!wasinside && isinside && getTrap("Enter") != null) putAndTriggerTrapsAndCatchExceptions("Enter", T);
- else if (wasinside && !isinside && getTrap("Leave") != null) putAndTriggerTrapsAndCatchExceptions("Leave", T);
- else if (wasinside && isinside && (mousex != oldmousex || mousey != oldmousey) && getTrap("Move")!= null)
- putAndTriggerTrapsAndCatchExceptions("Move", T);
- for(Box b = getChild(treeSize() - 1); b != null; b = b.prevSibling()) {
- b.Move(oldmousex - b.x, oldmousey - b.y, mousex - b.x, mousey - b.y, forceleave);
- if (b.inside(mousex - b.x, mousey - b.y)) forceleave = true;
- }
- }
-
// Reflow ////////////////////////////////////////////////////////////////////////////////////////
case "align": clear(ALIGNS); setAlign(value == null ? "center" : value); MARK_RESIZE;
case "cursor": setCursor(value);
case "fill": setFill(value);
- case "Press1": mouseEvent("Press1", value);
- case "Press2": mouseEvent("Press2", value);
- case "Press3": mouseEvent("Press3", value);
- case "Release1": mouseEvent("Release1", value);
- case "Release2": mouseEvent("Release2", value);
- case "Release3": mouseEvent("Release3", value);
- case "Click1": mouseEvent("Click1", value);
- case "Click2": mouseEvent("Click2", value);
- case "Click3": mouseEvent("Click3", value);
- case "DoubleClick1": mouseEvent("DoubleClick1", value);
- case "DoubleClick2": mouseEvent("DoubleClick2", value);
- case "DoubleClick3": mouseEvent("DoubleClick3", value);
case "Minimized": if (parent == null && getSurface() != null) getSurface().minimized = toBoolean(value); // FEATURE
case "Maximized": if (parent == null && getSurface() != null) getSurface().maximized = toBoolean(value); // FEATURE
case "Close": if (parent == null && getSurface() != null) getSurface().dispose(true);
case "fontsize": font = Font.getFont(font == null ? null : font.res, toInt(value)); MARK_RESIZE; dirty();
case "x": if (parent==null && Surface.fromBox(this)!=null) { CHECKSET_INT(x); } else { if (test(PACKED) && parent != null) return; CHECKSET_INT(x); dirty(); MARK_RESIZE; dirty(); }
case "y": if (parent==null && Surface.fromBox(this)!=null) { CHECKSET_INT(y); } else { if (test(PACKED) && parent != null) return; CHECKSET_INT(y); dirty(); MARK_RESIZE; dirty(); }
- case "KeyPressed": return; // prevent stuff from hitting the Hash
- case "KeyReleased": return; // prevent stuff from hitting the Hash
- case "PosChange": return; // prevent stuff from hitting the Hash
- case "SizeChange": return; // prevent stuff from hitting the Hash
- case "childadded": return; // prevent stuff from hitting the Hash
- case "childremoved": return; // prevent stuff from hitting the Hash
- case "thisbox": if (value == null) removeSelf();
- default: super.put(name, value);
+
+ case "Press1": if (!test(STOP_UPWARD_PROPAGATION) && parent != null) parent.put(name, value);
+ case "Press2": if (!test(STOP_UPWARD_PROPAGATION) && parent != null) parent.put(name, value);
+ case "Press3": if (!test(STOP_UPWARD_PROPAGATION) && parent != null) parent.put(name, value);
+ case "Release1": if (!test(STOP_UPWARD_PROPAGATION) && parent != null) parent.put(name, value);
+ case "Release2": if (!test(STOP_UPWARD_PROPAGATION) && parent != null) parent.put(name, value);
+ case "Release3": if (!test(STOP_UPWARD_PROPAGATION) && parent != null) parent.put(name, value);
+ case "Click1": if (!test(STOP_UPWARD_PROPAGATION) && parent != null) parent.put(name, value);
+ case "Click2": if (!test(STOP_UPWARD_PROPAGATION) && parent != null) parent.put(name, value);
+ case "Click3": if (!test(STOP_UPWARD_PROPAGATION) && parent != null) parent.put(name, value);
+ case "DoubleClick1": if (!test(STOP_UPWARD_PROPAGATION) && parent != null) parent.put(name, value);
+ case "DoubleClick2": if (!test(STOP_UPWARD_PROPAGATION) && parent != null) parent.put(name, value);
+ case "DoubleClick3": if (!test(STOP_UPWARD_PROPAGATION) && parent != null) parent.put(name, value);
+ case "KeyPressed": if (!test(STOP_UPWARD_PROPAGATION) && parent != null) parent.put(name, value);
+ case "KeyReleased": if (!test(STOP_UPWARD_PROPAGATION) && parent != null) parent.put(name, value);
+ case "Move": if (!test(STOP_UPWARD_PROPAGATION) && parent != null) parent.put(name, value);
+ case "Enter": if (!test(STOP_UPWARD_PROPAGATION) && parent != null) parent.put(name, value);
+ case "Leave": if (!test(STOP_UPWARD_PROPAGATION) && parent != null) parent.put(name, value);
+
+ case "_Move": propagateDownward(name, value, false);
+ case "_Press1": propagateDownward(name, value, false);
+ case "_Press2": propagateDownward(name, value, false);
+ case "_Press3": propagateDownward(name, value, false);
+ case "_Release1": propagateDownward(name, value, false);
+ case "_Release2": propagateDownward(name, value, false);
+ case "_Release3": propagateDownward(name, value, false);
+ case "_Click1": propagateDownward(name, value, false);
+ case "_Click2": propagateDownward(name, value, false);
+ case "_Click3": propagateDownward(name, value, false);
+ case "_DoubleClick1": propagateDownward(name, value, false);
+ case "_DoubleClick2": propagateDownward(name, value, false);
+ case "_DoubleClick3": propagateDownward(name, value, false);
+ case "_KeyPressed": propagateDownward(name, value, false);
+ case "_KeyReleased": propagateDownward(name, value, false);
+
+ case "PosChange": return;
+ case "SizeChange": return;
+ case "childadded": return;
+ case "childremoved": return;
+
+ case "thisbox": if (value == null) removeSelf();
+
+ default: super.put(name, value);
//#end
}
boxToCursor.put(this, value);
Surface surface = getSurface();
String tempcursor = surface.cursor;
- Move(surface.mousex, surface.mousey, surface.mousex, surface.mousey);
+ // FIXME
+ //Move(surface.mousex, surface.mousey, surface.mousex, surface.mousey);
if (surface.cursor != tempcursor) surface.syncCursor();
}
texture = Picture.load((Res)value, this);
}
-
- private void mouseEvent(String name, Object value) {
- Surface surface = getSurface();
- if (surface == null) return;
- int mousex = globalToLocalX(surface.mousex);
- int mousey = globalToLocalY(surface.mousey);
- for(Box c = prevSibling(); c != null; c = c.prevSibling())
- if (c.inside(mousex - c.x, mousey - c.y)) { c.putAndTriggerTrapsAndCatchExceptions(name, value); return; }
- if (parent != null) parent.putAndTriggerTrapsAndCatchExceptions(name, value);
+
+ /**
+ * Handles events which propagate down the box tree. If obscured
+ * is set, then we merely check for Enter/Leave.
+ */
+ private void propagateDownward(Object name_, Object value, boolean obscured) {
+
+ String name = (String)name_;
+ if (getSurface() == null) return;
+ int x = globalToLocalX(getSurface().mousex);
+ int y = globalToLocalY(getSurface().mousey);
+ boolean wasinside = test(MOUSEINSIDE);
+ boolean isinside = test(VISIBLE) && inside(x, y) && !obscured;
+ if (!wasinside && isinside) { set(MOUSEINSIDE); putAndTriggerTrapsAndCatchExceptions("Enter", T); }
+ if (wasinside && !isinside) { clear(MOUSEINSIDE); putAndTriggerTrapsAndCatchExceptions("Leave", T); }
+
+ boolean found = false;
+ if (wasinside || isinside)
+ for(Box child = getChild(treeSize() - 1); child != null; child = child.prevSibling()) {
+ boolean save_stop = child.test(STOP_UPWARD_PROPAGATION);
+ if (obscured || !child.inside(x - child.x, y - child.y)) {
+ child.propagateDownward(name, value, true);
+ } else try {
+ found = true;
+ child.clear(STOP_UPWARD_PROPAGATION);
+ child.putAndTriggerTrapsAndCatchExceptions(name, value);
+ } finally {
+ if (save_stop) child.set(STOP_UPWARD_PROPAGATION); else child.clear(STOP_UPWARD_PROPAGATION);
+ }
+ if (child.inside(x - child.x, y - child.y))
+ if (name.equals("_Move")) obscured = true;
+ else break;
+ }
+
+ if (!obscured && !found)
+ if (!name.equals("_Move") || wasinside) putAndTriggerTrapsAndCatchExceptions(name.substring(1), value);
}
private static int stringToColor(String s) {
}
}
- private void putAndTriggerTrapsAndCatchExceptions(Object name, Object val) {
+ void putAndTriggerTrapsAndCatchExceptions(Object name, Object val) {
try {
putAndTriggerTraps(name, val);
} catch (Exception e) {
// Instance Data ///////////////////////////////////////////////////////////////////////
- Vec keywatchers = new Vec();
-
public Box root; ///< The Box at the root of this surface
public String cursor = "default"; ///< The active cursor to switch to when syncCursor() is called
public int mousex; ///< x position of the mouse, in Scheduler-time
else if (button == 2) button2 = true;
else if (button == 3) button3 = true;
- if (button == 1) new SimpleMessage("Press1", T, Box.whoIs(root, mousex, mousey));
- else if (button == 2) new SimpleMessage("Press2", T, Box.whoIs(root, mousex, mousey));
+ if (button == 1) new SimpleMessage("_Press1", T, root);
+ else if (button == 2) new SimpleMessage("_Press2", T, root);
else if (button == 3) {
- final Box who = Box.whoIs(root, mousex, mousey);
+ final Box who = root;
Scheduler.add(new Scheduler.Task() { public void perform() throws JSExn {
Platform.clipboardReadEnabled = true;
try {
- root.putAndTriggerTraps("Press3", T);
+ root.putAndTriggerTraps("_Press3", T);
} finally {
Platform.clipboardReadEnabled = false;
}
else if (button == 2) button2 = false;
else if (button == 3) button3 = false;
- if (button == 1) new SimpleMessage("Release1", T, Box.whoIs(root, mousex, mousey));
- else if (button == 2) new SimpleMessage("Release2", T, Box.whoIs(root, mousex, mousey));
- else if (button == 3) new SimpleMessage("Release3", T, Box.whoIs(root, mousex, mousey));
+ if (button == 1) new SimpleMessage("_Release1", T, root);
+ else if (button == 2) new SimpleMessage("_Release2", T, root);
+ else if (button == 3) new SimpleMessage("_Release3", T, root);
if (Platform.needsAutoClick() && Math.abs(last_press_x - mousex) < 5 && Math.abs(last_press_y - mousey) < 5) Click(button);
last_press_x = Integer.MAX_VALUE;
}
protected final void Click(int button) {
- if (button == 1) new SimpleMessage("Click1", T, Box.whoIs(root, mousex, mousey));
- else if (button == 2) new SimpleMessage("Click2", T, Box.whoIs(root, mousex, mousey));
- else if (button == 3) new SimpleMessage("Click3", T, Box.whoIs(root, mousex, mousey));
+ if (button == 1) new SimpleMessage("_Click1", T, root);
+ else if (button == 2) new SimpleMessage("_Click2", T, root);
+ else if (button == 3) new SimpleMessage("_Click3", T, root);
if (Platform.needsAutoDoubleClick()) {
long now = System.currentTimeMillis();
if (lastClickButton == button && now - lastClickTime < 350) DoubleClick(button);
}
}
- protected final void DoubleClick(int button) {
- if (button == 1) new SimpleMessage("DoubleClick1", T, Box.whoIs(root, mousex, mousey));
- else if (button == 2) new SimpleMessage("DoubleClick2", T, Box.whoIs(root, mousex, mousey));
- else if (button == 3) new SimpleMessage("DoubleClick3", T, Box.whoIs(root, mousex, mousey));
- }
-
- /** Send a KeyPressed message; subclasses should not add the C- or A- prefixes or should they capitalize alphabet chars */
- protected final void KeyPressed(String key) {
- if (key == null) return;
- if (key.toLowerCase().endsWith("shift")) shift = true; else if (shift) key = key.toUpperCase();
- if (key.toLowerCase().equals("alt")) alt = true; else if (alt) key = "A-" + key;
- if (key.toLowerCase().endsWith("control")) control = true; else if (control) key = "C-" + key;
- Scheduler.add(new KMessage(key));
- }
-
- // This is implemented as a private static class instead of an anonymous class to work around a GCJ bug
- private class KMessage implements Scheduler.Task {
- String key = null;
- public KMessage(String k) { key = k; }
- public void perform() {
- if (key.equals("C-v") || key.equals("A-v")) Platform.clipboardReadEnabled = true;
- outer: for(int i=0; i<keywatchers.size(); i++) {
- Box b = (Box)keywatchers.elementAt(i);
- for(Box cur = b; cur != null; cur = cur.parent)
- if (!cur.test(cur.VISIBLE)) continue outer;
- try {
- b.putAndTriggerTraps("KeyPressed", key);
- } catch (JSExn e) {
- Log.log(Surface.class, "Exception thrown from KeyPressed handler");
- Log.logJS(e);
- }
- }
- Platform.clipboardReadEnabled = false;
- }
- }
-
- /** sends a KeyReleased message; subclasses should not add the C- or A- prefixes or capitalize alpha chars */
- protected final void KeyReleased(final String key) {
- if (key == null) return;
- if (key.toLowerCase().equals("alt")) alt = false;
- else if (key.toLowerCase().equals("control")) control = false;
- else if (key.toLowerCase().equals("shift")) shift = false;
- Scheduler.add(new Scheduler.Task() { public void perform() {
- outer: for(int i=0; i<keywatchers.size(); i++) {
- Box b = (Box)keywatchers.elementAt(i);
- for(Box cur = b; cur != null; cur = cur.parent)
- if (!cur.test(cur.VISIBLE)) continue outer;
- try {
- b.putAndTriggerTraps("KeyReleased", key);
- } catch (JSExn e) {
- Log.log(Surface.class, "Exception thrown from KeyReleased handler");
- Log.logJS(e);
- }
- }
- }});
- }
-
/** we enqueue ourselves in the Scheduler when we have a Move message to deal with */
public void perform() {
+ inqueue = false;
if (mousex == newmousex && mousey == newmousey) return;
int oldmousex = mousex; mousex = newmousex;
int oldmousey = mousey; mousey = newmousey;
// Root gets motion events outside itself (if trapped)
if (!root.inside(oldmousex, oldmousey) && !root.inside(mousex, mousey) && (button1 || button2 || button3))
try {
- root.putAndTriggerTraps("Move", T);
+ root.putAndTriggerTraps("_Move", T);
} catch (JSExn e) {
Log.log(Surface.class, "Exception thrown from Move message handler");
Log.logJS(e);
}
- root.Move(oldmousex, oldmousey, mousex, mousey);
if (!cursor.equals(oldcursor)) syncCursor();
}
protected final void Move(final int newmousex, final int newmousey) {
this.newmousex = newmousex;
this.newmousey = newmousey;
- Scheduler.add(this);
+ if (!inqueue) Scheduler.add(this);
+ inqueue = true;
}
+ boolean inqueue = false;
+ Scheduler.Task nextSizeChange = null;
+ int nextWidth = 0;
+ int nextHeight = 0;
// FEATURE: can we avoid creating objects here?
/** subclasses should invoke this method when the user resizes the window */
protected final void SizeChange(final int width, final int height) {
- Scheduler.addAtFront(new Scheduler.Task() { public void perform() {
+ nextWidth = width;
+ nextHeight = height;
+ if (nextSizeChange != null) return;
+ if (root.maxwidth == width && root.maxheight == height) return;
+ nextSizeChange = new Scheduler.Task() { public void perform() {
+ if (nextSizeChange != this) return;
// dirty the place where the scar used to be
root.dirty(0, root.maxheight - Main.scarImage.height, Main.scarImage.width, Main.scarImage.height);
- root.setMaxWidth(JS.N(width));
- root.setMaxHeight(JS.N(height));
- }});
+ root.setMaxWidth(JS.N(nextWidth));
+ root.setMaxHeight(JS.N(nextHeight));
+ nextSizeChange = null;
+ }};
+ Scheduler.add(nextSizeChange);
abort = true;
}
}});
}
+ private final String[] doubleClick = new String[] { null, "_DoubleClick1", "_DoubleClick2", "_DoubleClick3" };
+ protected final void DoubleClick(int button) { new SimpleMessage(doubleClick[button], T, root); }
+ protected final void KeyPressed(String key) { new SimpleMessage("_KeyPressed", key, root); }
+ protected final void KeyReleased(String key) { new SimpleMessage("_KeyReleased", key, root); }
protected final void Close() { new SimpleMessage("Close", T, root); }
protected final void Minimized(boolean b) { minimized = b; new SimpleMessage("Minimized", b ? T : F, root); }
protected final void Maximized(boolean b) { maximized = b; new SimpleMessage("Maximized", b ? T : F, root); }
protected final void Focused(boolean b) { new SimpleMessage("Focused", b ? T : F, root); }
- public static void Refresh() { Scheduler.add(renderAll); }
+ public static void Refresh() { /*Scheduler.add(renderAll);*/ }
public static final Scheduler.Task renderAll = new Scheduler.Task() { public void perform() {
for(int i=0; i<allSurfaces.size(); i++)
root.repack();
root.resize(root.x, root.y, root.maxwidth, root.maxheight);
root.resize_children();
- _setSize(root.width, root.height);
+ //_setSize(root.width, root.height);
String oldcursor = cursor;
cursor = "default";
- root.Move(mousex, mousey, mousex, mousey);
+ root.putAndTriggerTrapsAndCatchExceptions("_Move", JS.T);
if (!cursor.equals(oldcursor)) syncCursor();
} while(abort);
Scheduler.add(this);
}
- public void perform() throws JSExn { boxContainingMouse.putAndTriggerTraps(name, value); }
+ public void perform() {
+ if (name.equals("_KeyPressed")) {
+ String value = (String)this.value;
+ if (value.toLowerCase().endsWith("shift")) shift = true; else if (shift) value = value.toUpperCase();
+ if (value.toLowerCase().equals("alt")) alt = true; else if (alt) value = "A-" + value;
+ if (value.toLowerCase().endsWith("control")) control = true; else if (control) value = "C-" + value;
+ if (value.equals("C-v") || value.equals("A-v")) Platform.clipboardReadEnabled = true;
+ } else if (name.equals("_KeyReleased")) {
+ String value = (String)this.value;
+ if (value.toLowerCase().equals("alt")) alt = false;
+ else if (value.toLowerCase().equals("control")) control = false;
+ else if (value.toLowerCase().equals("shift")) shift = false;
+ }
+ try {
+ boxContainingMouse.putAndTriggerTraps(name, value);
+ } catch (JSExn e) {
+ Log.log(Surface.class, "Exception thrown from "+name+" handler");
+ Log.logJS(e);
+ } finally {
+ Platform.clipboardReadEnabled = false;
+ }
+ }
public String toString() { return "SimpleMessage [name=" + name + ", value=" + value + "]"; }
}
}
public void render() {
+ Dirty(0, 0, root.width, root.height);
super.render();
render_();
}