X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2FSurface.java;h=082bb8b3c3f7f4b782ad83b6ec828407b4297ce2;hb=94ec4ca482d8f8b2f20796b9bd01613250be89ef;hp=d8b944d2bc5af14bdd366eafc834ce3031e4822d;hpb=491a229b6fdd7b7785787199d2f0ed4f34c656ad;p=org.ibex.core.git diff --git a/src/org/xwt/Surface.java b/src/org/xwt/Surface.java index d8b944d..082bb8b 100644 --- a/src/org/xwt/Surface.java +++ b/src/org/xwt/Surface.java @@ -48,11 +48,11 @@ public abstract class Surface { /** true iff button 3 is depressed, in MessageQueue-time */ public static boolean button3 = false; + /** true iff all surfaces created from now on should be scarred */ + public static boolean scarAllSurfacesFromNowOn = false; - // Public Members and State Variables ///////////////////////////////////////////////////////// - /** this is the box on this surface which the mouse was inside at the time that the currently-executing event was enqueued */ - public Box boxContainingMouse = null; + // Public Members and State Variables ///////////////////////////////////////////////////////// /** false if the surface has never been rendered; used to determine if the surface should be repositioned to be centered on the screen */ public boolean centerSurfaceOnRender = true; @@ -92,7 +92,12 @@ public abstract class Surface { /** the y-position of the mouse the last time a Press message was enqueued */ int last_press_y = Integer.MAX_VALUE; + /** the last button to recieve a Click message; used for simulating DoubleClick's */ + static int lastClickButton = 0; + /** the last time a Click message was processed; used for simulating DoubleClick's */ + static long lastClickTime = 0; + // Methods to be overridden by subclasses /////////////////////////////////////////////////////// @@ -146,14 +151,13 @@ public abstract class Surface { else if (button == 2) button2 = true; else if (button == 3) button3 = true; - if (button == 1) new SimpleMessage("Press1", Boolean.TRUE, root.whoIs(mousex, mousey)); - else if (button == 2) new SimpleMessage("Press2", Boolean.TRUE, root.whoIs(mousex, mousey)); + if (button == 1) new SimpleMessage("Press1", Boolean.TRUE, Box.whoIs(root, mousex, mousey)); + else if (button == 2) new SimpleMessage("Press2", Boolean.TRUE, Box.whoIs(root, mousex, mousey)); else if (button == 3) { - final Box who = root.whoIs(mousex, mousey); + final Box who = Box.whoIs(root, mousex, mousey); MessageQueue.add(new Message() { public void perform() { - Surface.this.boxContainingMouse = who; Platform.clipboardReadEnabled = true; - root.put("Press1", null, Boolean.TRUE); + root.put("Press3", Boolean.TRUE); Platform.clipboardReadEnabled = false; }}); } @@ -164,9 +168,9 @@ public abstract class Surface { else if (button == 2) button2 = false; else if (button == 3) button3 = false; - if (button == 1) new SimpleMessage("Release1", Boolean.TRUE, root.whoIs(mousex, mousey)); - else if (button == 2) new SimpleMessage("Release2", Boolean.TRUE, root.whoIs(mousex, mousey)); - else if (button == 3) new SimpleMessage("Release3", Boolean.TRUE, root.whoIs(mousex, mousey)); + if (button == 1) new SimpleMessage("Release1", Boolean.TRUE, Box.whoIs(root, mousex, mousey)); + else if (button == 2) new SimpleMessage("Release2", Boolean.TRUE, Box.whoIs(root, mousex, mousey)); + else if (button == 3) new SimpleMessage("Release3", Boolean.TRUE, Box.whoIs(root, mousex, mousey)); 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; @@ -174,30 +178,36 @@ public abstract class Surface { } protected final void Click(int button) { - if (button == 1) new SimpleMessage("Click1", Boolean.TRUE, root.whoIs(mousex, mousey)); - else if (button == 2) new SimpleMessage("Click2", Boolean.TRUE, root.whoIs(mousex, mousey)); - else if (button == 3) new SimpleMessage("Click3", Boolean.TRUE, root.whoIs(mousex, mousey)); + if (button == 1) new SimpleMessage("Click1", Boolean.TRUE, Box.whoIs(root, mousex, mousey)); + else if (button == 2) new SimpleMessage("Click2", Boolean.TRUE, Box.whoIs(root, mousex, mousey)); + else if (button == 3) new SimpleMessage("Click3", Boolean.TRUE, Box.whoIs(root, mousex, mousey)); + if (Platform.needsAutoDoubleClick()) { + long now = System.currentTimeMillis(); + if (lastClickButton == button && now - lastClickTime < 350) DoubleClick(button); + lastClickButton = button; + lastClickTime = now; + } } protected final void DoubleClick(int button) { - if (button == 1) new SimpleMessage("DoubleClick1", Boolean.TRUE, root.whoIs(mousex, mousey)); - else if (button == 2) new SimpleMessage("DoubleClick2", Boolean.TRUE, root.whoIs(mousex, mousey)); - else if (button == 3) new SimpleMessage("DoubleClick3", Boolean.TRUE, root.whoIs(mousex, mousey)); + if (button == 1) new SimpleMessage("DoubleClick1", Boolean.TRUE, Box.whoIs(root, mousex, mousey)); + else if (button == 2) new SimpleMessage("DoubleClick2", Boolean.TRUE, Box.whoIs(root, mousex, mousey)); + else if (button == 3) new SimpleMessage("DoubleClick3", Boolean.TRUE, Box.whoIs(root, mousex, mousey)); } /** sends a KeyPressed message; subclasses should not add the C- or A- prefixes, nor should they capitalize alphabet characters */ protected final void KeyPressed(String key) { if (key == null) return; - if (key.equals("alt")) alt = true; + 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.endsWith("control")) control = true; + if (key.toLowerCase().endsWith("control")) control = true; else if (control) key = "C-" + key; - if (key.endsWith("shift")) shift = true; - else if (shift) key = key.toUpperCase(); - final String fkey = key; MessageQueue.add(new KMessage(key)); } @@ -212,7 +222,7 @@ public abstract class Surface { Box b = (Box)keywatchers.elementAt(i); for(Box cur = b; cur != null; cur = cur.getParent()) if (cur.invisible) continue outer; - b.put("KeyPressed", null, key); + b.put("KeyPressed", key); } Platform.clipboardReadEnabled = false; } @@ -221,15 +231,15 @@ public abstract class Surface { /** sends a KeyReleased message; subclasses should not add the C- or A- prefixes, nor should they capitalize alphabet characters */ protected final void KeyReleased(final String key) { if (key == null) return; - if (key.equals("alt")) alt = false; - else if (key.equals("control")) control = false; - else if (key.equals("shift")) shift = false; + if (key.toLowerCase().equals("alt")) alt = false; + else if (key.toLowerCase().equals("control")) control = false; + else if (key.toLowerCase().equals("shift")) shift = false; MessageQueue.add(new Message() { public void perform() { outer: for(int i=0; i height - scarPicture.getHeight() - vscar) { int _x1 = Math.max(x, hscar); int _x2 = Math.min(x + w, hscar + scarPicture.getWidth()); @@ -509,8 +530,8 @@ public abstract class Surface { int h = dirt[i][3]; if (x < 0) x = 0; if (y < 0) y = 0; - if (x+w > root.size(0)) w = root.size(0) - x; - if (y+h > root.size(1)) h = root.size(1) - y; + if (x+w > root.width) w = root.width - x; + if (y+h > root.height) h = root.height - y; if (w <= 0 || h <= 0) continue; // if any part of this region falls within the "bad region", just skip it @@ -551,11 +572,11 @@ public abstract class Surface { } // FEATURE: reinstate recycler - private class SimpleMessage implements Message { + public class SimpleMessage implements Message { private Box boxContainingMouse; private Object value; - private String name; + public String name; SimpleMessage(String name, Object value, Box boxContainingMouse) { this.boxContainingMouse = boxContainingMouse; @@ -564,14 +585,8 @@ public abstract class Surface { MessageQueue.add(this); } - public void perform() { - Surface.this.boxContainingMouse = this.boxContainingMouse; - root.put(name, root, value); - } - - public String toString() { - return "SimpleMessage [name=" + name + ", value=" + value + "]"; - } + public void perform() { boxContainingMouse.put(name, value); } + public String toString() { return "SimpleMessage [name=" + name + ", value=" + value + "]"; } }