// 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_();
}