2003/12/17 00:27:26
[org.ibex.core.git] / src / org / xwt / Surface.java
index be36370..f3891ad 100644 (file)
@@ -92,10 +92,13 @@ public abstract class Surface extends PixelBuffer implements Scheduler.Task {
         else if (button == 2) new SimpleMessage("Press2", T, Box.whoIs(root, mousex, mousey));
         else if (button == 3) {
             final Box who = Box.whoIs(root, mousex, mousey);
-            Scheduler.add(new Scheduler.Task() { public void perform() {
+            Scheduler.add(new Scheduler.Task() { public void perform() throws JSExn {
                 Platform.clipboardReadEnabled = true;
-                root.putAndTriggerTraps("Press3", T);
-                Platform.clipboardReadEnabled = false;
+                try {
+                    root.putAndTriggerTraps("Press3", T);
+                } finally {
+                    Platform.clipboardReadEnabled = false;
+                }
             }});
         }
     }
@@ -151,7 +154,12 @@ public abstract class Surface extends PixelBuffer implements Scheduler.Task {
                 Box b = (Box)keywatchers.elementAt(i);
                 for(Box cur = b; cur != null; cur = cur.parent)
                     if (!cur.test(cur.VISIBLE)) continue outer;
-                b.putAndTriggerTraps("KeyPressed", key);
+                try {
+                    b.putAndTriggerTraps("KeyPressed", key);
+                } catch (JSExn e) {
+                    Log.log(Surface.class, "Exception thrown from KeyPressed handler");
+                    Log.logJS(e);
+                }
             }
             Platform.clipboardReadEnabled = false;
         }
@@ -168,7 +176,12 @@ public abstract class Surface extends PixelBuffer implements Scheduler.Task {
                 Box b = (Box)keywatchers.elementAt(i);
                 for(Box cur = b; cur != null; cur = cur.parent)
                     if (!cur.test(cur.VISIBLE)) continue outer;
-                b.putAndTriggerTraps("KeyReleased", key);
+                try {
+                    b.putAndTriggerTraps("KeyReleased", key);
+                } catch (JSExn e) {
+                    Log.log(Surface.class, "Exception thrown from KeyReleased handler");
+                    Log.logJS(e);
+                }
             }
         }});
     }
@@ -181,7 +194,12 @@ public abstract class Surface extends PixelBuffer implements Scheduler.Task {
         String oldcursor = cursor;  cursor = "default";
         // Root gets motion events outside itself (if trapped)
         if (!root.inside(oldmousex, oldmousey) && !root.inside(mousex, mousey) && (button1 || button2 || button3))
-            root.putAndTriggerTraps("Move", T);
+            try {
+                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();
     }
@@ -199,20 +217,20 @@ public abstract class Surface extends PixelBuffer implements Scheduler.Task {
     }
 
     // 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() {
             // 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.set(root.REFLOW);
         }});
         abort = true;
     }
 
     // FEATURE: can we avoid creating objects here?
     protected final void PosChange(final int x, final int y) {
-        Scheduler.add(new Scheduler.Task() { public void perform() {
+        Scheduler.add(new Scheduler.Task() { public void perform() throws JSExn {
             root.x = x;
             root.y = y;
             root.putAndTriggerTraps("PosChange", T);
@@ -336,7 +354,7 @@ public abstract class Surface extends PixelBuffer implements Scheduler.Task {
             Scheduler.add(this);
         }
         
-        public void perform() { boxContainingMouse.putAndTriggerTraps(name, value); }
+        public void perform() throws JSExn { boxContainingMouse.putAndTriggerTraps(name, value); }
         public String toString() { return "SimpleMessage [name=" + name + ", value=" + value + "]"; }
 
     }