mousewheel support on all platforms (X11,Darwin,Win32,Java14) and in the core (bug...
authoradam <adam@megacz.com>
Tue, 10 Feb 2004 02:23:27 +0000 (02:23 +0000)
committeradam <adam@megacz.com>
Tue, 10 Feb 2004 02:23:27 +0000 (02:23 +0000)
darcs-hash:20040210022327-5007d-addf7e206fd7f03b6cc7a47de87e39756e3055d3.gz

src/org/ibex/Box.java
src/org/ibex/Surface.java
src/org/ibex/plat/Darwin.cc
src/org/ibex/plat/Java2.java
src/org/ibex/plat/Win32.cc
src/org/ibex/plat/X11.cc

index 1b10383..6bd6ddf 100644 (file)
@@ -166,6 +166,7 @@ public final class Box extends JSScope implements Scheduler.Task {
 
     // Instance Methods /////////////////////////////////////////////////////////////////////
 
+    public int fontSize() { return (font == null ? DEFAULT_FONT : font).pointsize; }
 
     /** invoked when a resource needed to render ourselves finishes loading */
     public void perform() throws JSExn {
@@ -566,6 +567,11 @@ public final class Box extends JSScope implements Scheduler.Task {
         case "Enter":         if (!test(STOP_UPWARD_PROPAGATION) && parent != null) parent.putAndTriggerTraps(name, value);
         case "Leave":         if (!test(STOP_UPWARD_PROPAGATION) && parent != null) parent.putAndTriggerTraps(name, value);
 
+        case "HScroll":       if (!test(STOP_UPWARD_PROPAGATION) && parent != null)
+            parent.putAndTriggerTraps(name, N(((Number)value).floatValue() * ((float)parent.fontSize()) / ((float)fontSize())));
+        case "VScroll":       if (!test(STOP_UPWARD_PROPAGATION) && parent != null)
+            parent.putAndTriggerTraps(name, N(((Number)value).floatValue() * ((float)parent.fontSize()) / ((float)fontSize())));
+
         case "_Move":         propagateDownward(name, value, false);
         case "_Press1":       propagateDownward(name, value, false);
         case "_Press2":       propagateDownward(name, value, false);
@@ -581,6 +587,8 @@ public final class Box extends JSScope implements Scheduler.Task {
         case "_DoubleClick3": propagateDownward(name, value, false);
         case "_KeyPressed":   propagateDownward(name, value, false);
         case "_KeyReleased":  propagateDownward(name, value, false);
+        case "_HScroll":      propagateDownward(name, value, false);
+        case "_VScroll":      propagateDownward(name, value, false);
 
         case "PosChange":     return;
         case "SizeChange":    return;
@@ -681,13 +689,16 @@ public final class Box extends JSScope implements Scheduler.Task {
         if (wasinside || isinside)
             for(Box child = getChild(treeSize() - 1); child != null; child = child.prevSibling()) {
                 boolean save_stop = child.test(STOP_UPWARD_PROPAGATION);
+                Object value2 = value;
+                if (name.equals("_HScroll") || name.equals("_VScroll"))
+                    value2 = N(((Number)value).floatValue() * ((float)child.fontSize()) / (float)fontSize());
                 if (obscured || !child.inside(x - child.x, y - child.y)) {
-                    child.propagateDownward(name, value, true);
+                    child.propagateDownward(name, value2, true);
                 } else try {
                     found = true;
                     child.clear(STOP_UPWARD_PROPAGATION);
-                    if (name != null) child.putAndTriggerTrapsAndCatchExceptions(name, value);
-                    else child.propagateDownward(name, value, obscured);
+                    if (name != null) child.putAndTriggerTrapsAndCatchExceptions(name, value2);
+                    else child.propagateDownward(name, value2, obscured);
                 } finally {
                     if (save_stop) child.set(STOP_UPWARD_PROPAGATION); else child.clear(STOP_UPWARD_PROPAGATION);
                 }
index 2d577e6..48eb198 100644 (file)
@@ -149,6 +149,11 @@ public abstract class Surface extends PixelBuffer implements Scheduler.Task {
         Scheduler.add(this);
     }
 
+    protected final void HScroll(int pixels) { new Message("_HScroll", new Integer(pixels), root); }
+    protected final void VScroll(int pixels) { new Message("_VScroll", new Integer(pixels), root); }
+    protected final void HScroll(float lines) { new Message("_HScroll", new Float(lines), root); }
+    protected final void VScroll(float lines) { new Message("_VScroll", new Float(lines), root); }
+
     /** subclasses should invoke this method when the user resizes the window */
     protected final void SizeChange(final int width, final int height) {
         if (pendingWidth == width && pendingHeight == height) return;
@@ -300,6 +305,10 @@ public abstract class Surface extends PixelBuffer implements Scheduler.Task {
                 else if (value.toLowerCase().equals("control")) control = false;
                 else if (value.toLowerCase().equals("shift")) shift = false;
                 this.value = value;
+            } else if (name.equals("_HScroll") || name.equals("_VScroll")) {
+                // FIXME: technically points != pixels
+                if (value instanceof Integer)
+                    value = new Float(((Integer)value).intValue() * root.fontSize());
             }
             try {
                 boxContainingMouse.putAndTriggerTrapsAndCatchExceptions(name, value);
index 7adf0ee..67400e1 100644 (file)
@@ -587,11 +587,12 @@ static OSStatus windowEventHandler(EventHandlerCallRef handler, EventRef e, void
                     SInt32 delta;
                     r = WC(GetEventParameter)(e,kEventParamMouseWheelAxis,typeMouseWheelAxis,NULL,sizeof(axis),NULL,&axis);
                     checkStatus(r,"GetEventParameter");
-                    if(axis != kEventMouseWheelAxisY) break;
                     r = WC(GetEventParameter)(e,kEventParamMouseWheelDelta,typeSInt32,NULL,sizeof(delta),NULL,&delta);
                     checkStatus(r,"GetEventParameter");
-                    fprintf(stderr,"kEventMouseWheelMoved: delta: %d",delta);
-                    // surface->MouseWheelMoved(...) IMPROVMENT: mouse wheel support in ibex
+                    switch(axis) {
+                      case kEventMouseWheelAxisX: surface->HScroll(40 * delta); break;
+                      case kEventMouseWheelAxisY: surface->VScroll(40 * delta); break;
+                    }
                     return noErr;
                 }
             }
index f63317e..0263a5b 100644 (file)
@@ -20,7 +20,7 @@ public class Java2 extends AWT {
         // disable the focus manager so we can intercept the tab key
         String versionString = System.getProperty("java.version", "");
         int secondDecimal = versionString.substring(versionString.indexOf('.') + 1).indexOf('.');
-        if (secondDecimal != -1) versionString = versionString.substring(0, secondDecimal);
+        if (secondDecimal != -1) versionString = versionString.substring(0, versionString.indexOf('.') + 1 + secondDecimal);
         double version = Double.parseDouble(versionString);
         if (version >= 1.4) {
             isJava14 = true;
@@ -159,8 +159,8 @@ public class Java2 extends AWT {
         }
 
         public void mouseWheelMoved(MouseWheelEvent m) {
-            // TODO: Uncomment this once Scroll is implemented in the core
-            //if(m.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) { Scroll(m.getUnitsToScroll()); }
+            if (m.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL)
+                VScroll(m.getUnitsToScroll());
         }
     }
 
index fda911b..a4d10fa 100644 (file)
@@ -637,7 +637,9 @@ jint org::ibex::plat::Win32$Win32Surface::WndProc(jint _hwnd, jint _iMsg, jint _
     switch(iMsg) {
     case WM_DEVMODECHANGE: break;    // FEATURE: color depth changed
     case WM_DISPLAYCHANGE: break;    // FEATURE: screen size changed
-    case WM_MOUSEWHEEL: break;       // FEATURE: Mouse Wheel
+    case WM_MOUSEWHEEL:
+      VScroll(((jfloat)((wParam & 0xffff0000) >> 16)) / (jfloat)120);
+      break;
 
     case WM_SYSKEYDOWN: if (GetKeyState(VK_MENU) >> (sizeof(SHORT) * 8 - 1) == 0) return 0;
     case WM_KEYDOWN:
index 81e61fb..0252a81 100644 (file)
@@ -526,6 +526,12 @@ void org::ibex::plat::X11$X11Surface::dispatchEvent(gnu::gcj::RawData* ev) {
         
     } else if (e->type == ButtonPress) {
         XButtonEvent* xbe = (XButtonEvent*)(e);
+        switch(xbe->button) {
+          case 4: VScroll((jfloat)-1.0); return;
+          case 5: VScroll((jfloat)1.0); return;
+          case 6: HScroll((jfloat)-1.0); return;
+          case 7: HScroll((jfloat)1.0); return;
+        }
         if (xbe->button == 2) xbe->button = 3;
         else if (xbe->button == 3) xbe->button = 2;
         Press(xbe->button);