2002/08/07 04:31:04
[org.ibex.core.git] / src / org / xwt / Surface.java
index d8b944d..da783c1 100644 (file)
@@ -92,6 +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 ///////////////////////////////////////////////////////
@@ -153,7 +159,7 @@ public abstract class Surface {
             MessageQueue.add(new Message() { public void perform() {
                 Surface.this.boxContainingMouse = who;
                 Platform.clipboardReadEnabled = true;
-                root.put("Press1", null, Boolean.TRUE);
+                root.put("Press3", null, Boolean.TRUE);
                 Platform.clipboardReadEnabled = false;
             }});
         }
@@ -177,6 +183,12 @@ public abstract class Surface {
         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 (Platform.needsAutoDoubleClick()) {
+            long now = System.currentTimeMillis();
+            if (lastClickButton == button && now - lastClickTime < 350) DoubleClick(button);
+            lastClickButton = button;
+            lastClickTime = now;
+        }
     }
 
     protected final void DoubleClick(int button) {
@@ -189,15 +201,15 @@ public abstract class Surface {
     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));
     }
@@ -221,9 +233,9 @@ 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<keywatchers.size(); i++) {
                 Box b = (Box)keywatchers.elementAt(i);
@@ -345,6 +357,8 @@ public abstract class Surface {
 
     /** wrapper for setSize() which makes sure to dirty the place where the scar used to be */
     void _setSize(int width, int height) {
+        width = Math.max(width, scarPicture.getWidth());
+        height = Math.max(height, scarPicture.getHeight());
         dirty(hscar,
               root.size(1) - vscar - scarPicture.getHeight(),
               scarPicture.getWidth(), scarPicture.getHeight());
@@ -551,11 +565,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;