2003/12/17 00:27:26
authormegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:43:00 +0000 (07:43 +0000)
committermegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:43:00 +0000 (07:43 +0000)
darcs-hash:20040130074300-2ba56-a7e835fab0e6d4a30658a099d3cbef514b9dc12c.gz

src/org/xwt/Box.java
src/org/xwt/Surface.java

index 8287e45..d6bb5f5 100644 (file)
@@ -205,10 +205,10 @@ public final class Box extends JSScope implements Scheduler.Task {
         if (!wasinside && !isinside) return;
         
         if (isinside && test(CURSOR)) Surface.fromBox(getRoot()).cursor = (String)boxToCursor.get(this);
-        if (!wasinside && isinside && getTrap("Enter") != null) putAndTriggerTraps("Enter", T);
-        else if (wasinside && !isinside && getTrap("Leave") != null) putAndTriggerTraps("Leave", T);
+        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)
-            putAndTriggerTraps("Move", T);
+            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;
@@ -271,10 +271,8 @@ public final class Box extends JSScope implements Scheduler.Task {
             boolean poschange = (this.x != x || this.y != y) && getTrap("PosChange") != null;
             this.width = width; this.height = height; this.x = x; this.y = y;
             dirty();
-            if (sizechange) try { putAndTriggerTraps("SizeChange", T); /*Surface.abort = true;*/ }
-                catch (Exception e) { Log.log(this, e); }
-            if (poschange) try { putAndTriggerTraps("PosChange", T); /*Surface.abort = true;*/ }
-                catch (Exception e) { Log.log(this, e); }
+            if (sizechange) putAndTriggerTrapsAndCatchExceptions("SizeChange", T);
+            if (poschange)  putAndTriggerTrapsAndCatchExceptions("PosChange", T);
             //}
     }
 
@@ -599,8 +597,8 @@ public final class Box extends JSScope implements Scheduler.Task {
         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.putAndTriggerTraps(name, value); return; }
-        if (parent != null) parent.putAndTriggerTraps(name, value);
+            if (c.inside(mousex - c.x, mousey - c.y)) { c.putAndTriggerTrapsAndCatchExceptions(name, value); return; }
+        if (parent != null) parent.putAndTriggerTrapsAndCatchExceptions(name, value);
     }
 
     private static int stringToColor(String s) {
@@ -707,7 +705,7 @@ public final class Box extends JSScope implements Scheduler.Task {
         deleteNode(i);
         b.parent = null;
         MARK_REFLOW;
-        putAndTriggerTraps("childremoved", b);
+        putAndTriggerTrapsAndCatchExceptions("childremoved", b);
     }
     
     public void put(int i, Object value) throws JSExn {
@@ -719,22 +717,22 @@ public final class Box extends JSScope implements Scheduler.Task {
         }
 
         if (redirect == null) {
-            if (value == null) putAndTriggerTraps("childremoved", getChild(i));
+            if (value == null) putAndTriggerTrapsAndCatchExceptions("childremoved", getChild(i));
             else Log.logJS(this, "attempt to add/remove children to/from a node with a null redirect");
 
         } else if (redirect != this) {
-            if (value != null) putAndTriggerTraps("childadded", value);
+            if (value != null) putAndTriggerTrapsAndCatchExceptions("childadded", value);
             redirect.put(i, value);
             if (value == null) {
                 Box b = (Box)redirect.get(new Integer(i));
-                if (b != null) putAndTriggerTraps("childremoved", b);
+                if (b != null) putAndTriggerTrapsAndCatchExceptions("childremoved", b);
             }
 
         } else if (value == null) {
             if (i < 0 || i > treeSize()) return;
             Box b = getChild(i);
             removeChild(i);
-            putAndTriggerTraps("childremoved", b);
+            putAndTriggerTrapsAndCatchExceptions("childremoved", b);
 
         } else {
             Box b = (Box)value;
@@ -763,29 +761,19 @@ public final class Box extends JSScope implements Scheduler.Task {
             MARK_REFLOW;
             
             b.dirty(); 
-            putAndTriggerTraps("childadded", b);
+            putAndTriggerTrapsAndCatchExceptions("childadded", b);
         }
     }
 
-
-    public final void putAndTriggerTraps(Object key, Object value) {
+    private void putAndTriggerTrapsAndCatchExceptions(Object name, Object val) {
         try {
-            super.putAndTriggerTraps(key, value);
-        } catch (JSExn jse) {
-            Log.logJS("attempt to put value " + value + " to key " + key + " on a box triggered a trap which threw:");
-            Log.logJS(jse);
+            putAndTriggerTraps(name, val);
+        } catch (Exception e) {
+            Log.logJS("caught exception while putting to trap \""+name+"\"");
+            Log.logJS(e);
         }
     }
 
-    public final Object getAndTriggerTraps(Object key) {
-        try {
-            return super.getAndTriggerTraps(key);
-        } catch (JSExn jse) {
-            Log.logJS("attempt to get key " + key + " on a box triggered a trap which threw:");
-            Log.logJS(jse);
-            return null;
-        }
-    }
 }
 
 
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 + "]"; }
 
     }