aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitri Trembovetski <[email protected]>2009-05-25 00:10:13 +0000
committerDmitri Trembovetski <[email protected]>2009-05-25 00:10:13 +0000
commitbeaa6d5d02d747c2eda1a3a81ba5e4030c9c5587 (patch)
tree2e3551c56d2850af07ab6b4890f0a596506d3c55
parent1d428d4fce17329e7d3cc212ae45729836c07a25 (diff)
Newt fixes: implemented mouse wheel support - currently only hooked up on Windows platform, others will follow
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JOGL_2_SANDBOX@1913 232f8b59-042b-4e1e-8c03-345bb8c30851
-rw-r--r--src/newt/classes/com/sun/javafx/newt/InputEvent.java25
-rw-r--r--src/newt/classes/com/sun/javafx/newt/MouseEvent.java22
-rw-r--r--src/newt/classes/com/sun/javafx/newt/MouseListener.java1
-rwxr-xr-xsrc/newt/classes/com/sun/javafx/newt/Window.java20
-rw-r--r--src/newt/classes/com/sun/javafx/newt/awt/AWTWindow.java8
-rwxr-xr-xsrc/newt/native/KDWindow.c6
-rw-r--r--src/newt/native/MouseEvent.h2
-rw-r--r--src/newt/native/NewtMacWindow.m4
-rwxr-xr-xsrc/newt/native/WindowsWindow.c80
9 files changed, 128 insertions, 40 deletions
diff --git a/src/newt/classes/com/sun/javafx/newt/InputEvent.java b/src/newt/classes/com/sun/javafx/newt/InputEvent.java
index dc36be34d..b49c72e75 100644
--- a/src/newt/classes/com/sun/javafx/newt/InputEvent.java
+++ b/src/newt/classes/com/sun/javafx/newt/InputEvent.java
@@ -35,11 +35,14 @@ package com.sun.javafx.newt;
public abstract class InputEvent extends Event
{
- public static int SHIFT_MASK = 1 << 0;
- public static int CTRL_MASK = 1 << 1;
- public static int META_MASK = 1 << 2;
- public static int ALT_MASK = 1 << 3;
- public static int ALT_GRAPH_MASK = 1 << 5;
+ public static final int SHIFT_MASK = 1 << 0;
+ public static final int CTRL_MASK = 1 << 1;
+ public static final int META_MASK = 1 << 2;
+ public static final int ALT_MASK = 1 << 3;
+ public static final int ALT_GRAPH_MASK = 1 << 5;
+ public static final int BUTTON1_MASK = 1 << 6;
+ public static final int BUTTON2_MASK = 1 << 7;
+ public static final int BUTTON3_MASK = 1 << 8;
protected InputEvent(boolean sysEvent, int eventType, Window source, long when, int modifiers) {
super(sysEvent, eventType, source, when);
@@ -73,6 +76,18 @@ public abstract class InputEvent extends Event
return (modifiers&SHIFT_MASK)!=0;
}
+ public boolean isButton1Down() {
+ return (modifiers&BUTTON1_MASK)!=0;
+ }
+
+ public boolean isButton2Down() {
+ return (modifiers&BUTTON2_MASK)!=0;
+ }
+
+ public boolean isButton3Down() {
+ return (modifiers&BUTTON3_MASK)!=0;
+ }
+
public String toString() {
return "InputEvent[modifiers:"+modifiers+"]";
}
diff --git a/src/newt/classes/com/sun/javafx/newt/MouseEvent.java b/src/newt/classes/com/sun/javafx/newt/MouseEvent.java
index 79e11b875..ede193e1c 100644
--- a/src/newt/classes/com/sun/javafx/newt/MouseEvent.java
+++ b/src/newt/classes/com/sun/javafx/newt/MouseEvent.java
@@ -43,16 +43,21 @@ public class MouseEvent extends InputEvent
public static final int BUTTON6 = 6;
public static final int BUTTON_NUMBER = 6;
- protected MouseEvent(boolean sysEvent, int eventType, Window source, long when, int modifiers, int x, int y, int clickCount, int button)
+ protected MouseEvent(boolean sysEvent, int eventType, Window source, long when,
+ int modifiers, int x, int y, int clickCount, int button,
+ int rotation)
{
super(sysEvent, eventType, source, when, modifiers);
this.x=x;
this.y=y;
this.clickCount=clickCount;
this.button=button;
+ this.wheelRotation = rotation;
}
- public MouseEvent(int eventType, Window source, long when, int modifiers, int x, int y, int clickCount, int button) {
- this(false, eventType, source, when, modifiers, x, y, clickCount, button);
+ public MouseEvent(int eventType, Window source, long when, int modifiers,
+ int x, int y, int clickCount, int button, int rotation) {
+ this(false, eventType, source, when, modifiers, x, y, clickCount, button,
+ rotation);
}
public int getButton() {
@@ -67,10 +72,15 @@ public class MouseEvent extends InputEvent
public int getY() {
return y;
}
+ public int getWheelRotation() {
+ return wheelRotation;
+ }
public String toString() {
return "MouseEvent["+getEventTypeString(getEventType())+
- ", "+x+"/"+y+", button "+button+", count "+clickCount+", "+super.toString()+"]";
+ ", "+x+"/"+y+", button "+button+", count "+clickCount+
+ ", wheel rotation "+wheelRotation+
+ ", "+super.toString()+"]";
}
public static String getEventTypeString(int type) {
@@ -82,11 +92,12 @@ public class MouseEvent extends InputEvent
case EVENT_MOUSE_RELEASED: return "EVENT_MOUSE_RELEASED";
case EVENT_MOUSE_MOVED: return "EVENT_MOUSE_MOVED";
case EVENT_MOUSE_DRAGGED: return "EVENT_MOUSE_DRAGGED";
+ case EVENT_MOUSE_WHEEL_MOVED: return "EVENT_MOUSE_WHEEL_MOVED";
default: return "unknown (" + type + ")";
}
}
- private int x, y, clickCount, button;
+ private int x, y, clickCount, button, wheelRotation;
public static final int EVENT_MOUSE_CLICKED = 200;
public static final int EVENT_MOUSE_ENTERED = 201;
@@ -95,4 +106,5 @@ public class MouseEvent extends InputEvent
public static final int EVENT_MOUSE_RELEASED = 204;
public static final int EVENT_MOUSE_MOVED = 205;
public static final int EVENT_MOUSE_DRAGGED = 206;
+ public static final int EVENT_MOUSE_WHEEL_MOVED = 207;
}
diff --git a/src/newt/classes/com/sun/javafx/newt/MouseListener.java b/src/newt/classes/com/sun/javafx/newt/MouseListener.java
index f707979ba..3d2031f2a 100644
--- a/src/newt/classes/com/sun/javafx/newt/MouseListener.java
+++ b/src/newt/classes/com/sun/javafx/newt/MouseListener.java
@@ -42,5 +42,6 @@ public interface MouseListener extends EventListener
public void mouseReleased(MouseEvent e);
public void mouseMoved(MouseEvent e);
public void mouseDragged(MouseEvent e);
+ public void mouseWheelMoved(MouseEvent e);
}
diff --git a/src/newt/classes/com/sun/javafx/newt/Window.java b/src/newt/classes/com/sun/javafx/newt/Window.java
index 8c6d92fe5..29d4b6195 100755
--- a/src/newt/classes/com/sun/javafx/newt/Window.java
+++ b/src/newt/classes/com/sun/javafx/newt/Window.java
@@ -427,7 +427,8 @@ public abstract class Window implements NativeWindow
private int lastMouseClickCount = 0; // last mouse button click count
public static final int ClickTimeout = 300;
- protected void sendMouseEvent(int eventType, int modifiers, int x, int y, int button) {
+ protected void sendMouseEvent(int eventType, int modifiers,
+ int x, int y, int button, int rotation) {
if(DEBUG_MOUSE_EVENT) {
System.out.println("sendMouseEvent: "+MouseEvent.getEventTypeString(eventType)+
", mod "+modifiers+", pos "+x+"/"+y+", button "+button);
@@ -448,13 +449,13 @@ public abstract class Window implements NativeWindow
lastMousePressed=when;
mouseButtonPressed=button;
e = new MouseEvent(true, eventType, this, when,
- modifiers, x, y, lastMouseClickCount, button);
+ modifiers, x, y, lastMouseClickCount, button, 0);
} else if(MouseEvent.EVENT_MOUSE_RELEASED==eventType) {
e = new MouseEvent(true, eventType, this, when,
- modifiers, x, y, lastMouseClickCount, button);
+ modifiers, x, y, lastMouseClickCount, button, 0);
if(when-lastMousePressed<ClickTimeout) {
eClicked = new MouseEvent(true, MouseEvent.EVENT_MOUSE_CLICKED, this, when,
- modifiers, x, y, lastMouseClickCount, button);
+ modifiers, x, y, lastMouseClickCount, button, 0);
} else {
lastMouseClickCount=0;
lastMousePressed=0;
@@ -463,13 +464,15 @@ public abstract class Window implements NativeWindow
} else if(MouseEvent.EVENT_MOUSE_MOVED==eventType) {
if (mouseButtonPressed>0) {
e = new MouseEvent(true, MouseEvent.EVENT_MOUSE_DRAGGED, this, when,
- modifiers, x, y, 1, mouseButtonPressed);
+ modifiers, x, y, 1, mouseButtonPressed, 0);
} else {
e = new MouseEvent(true, eventType, this, when,
- modifiers, x, y, 0, button);
+ modifiers, x, y, 0, button, 0);
}
+ } else if(MouseEvent.EVENT_MOUSE_WHEEL_MOVED==eventType) {
+ e = new MouseEvent(true, eventType, this, when, modifiers, x, y, 0, button, rotation);
} else {
- e = new MouseEvent(true, eventType, this, when, modifiers, x, y, 0, button);
+ e = new MouseEvent(true, eventType, this, when, modifiers, x, y, 0, button, 0);
}
if(DEBUG_MOUSE_EVENT) {
@@ -510,6 +513,9 @@ public abstract class Window implements NativeWindow
case MouseEvent.EVENT_MOUSE_DRAGGED:
l.mouseDragged(e);
break;
+ case MouseEvent.EVENT_MOUSE_WHEEL_MOVED:
+ l.mouseWheelMoved(e);
+ break;
default:
throw new NativeWindowException("Unexpected mouse event type " + e.getEventType());
}
diff --git a/src/newt/classes/com/sun/javafx/newt/awt/AWTWindow.java b/src/newt/classes/com/sun/javafx/newt/awt/AWTWindow.java
index bd29d7576..9e539da8a 100644
--- a/src/newt/classes/com/sun/javafx/newt/awt/AWTWindow.java
+++ b/src/newt/classes/com/sun/javafx/newt/awt/AWTWindow.java
@@ -189,10 +189,16 @@ public class AWTWindow extends Window {
case com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_RELEASED:
case com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_MOVED:
case com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_DRAGGED:
+ case com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_WHEEL_MOVED:
if ((eventMask & com.sun.javafx.newt.EventListener.MOUSE) != 0) {
MouseEvent e = (MouseEvent) w.getEvent();
+ int rotation = 0;
+ if (e instanceof MouseWheelEvent) {
+ rotation = ((MouseWheelEvent)e).getWheelRotation();
+ }
sendMouseEvent(w.getType(), convertModifiers(e),
- e.getX(), e.getY(), convertButton(e));
+ e.getX(), e.getY(), convertButton(e),
+ rotation);
}
break;
diff --git a/src/newt/native/KDWindow.c b/src/newt/native/KDWindow.c
index 8e4764c49..e5fb41a76 100755
--- a/src/newt/native/KDWindow.c
+++ b/src/newt/native/KDWindow.c
@@ -97,7 +97,7 @@ JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_kd_KDWindow_initIDs
sizeChangedID = (*env)->GetMethodID(env, clazz, "sizeChanged", "(II)V");
windowDestroyNotifyID = (*env)->GetMethodID(env, clazz, "windowDestroyNotify", "()V");
windowDestroyedID = (*env)->GetMethodID(env, clazz, "windowDestroyed", "()V");
- sendMouseEventID = (*env)->GetMethodID(env, clazz, "sendMouseEvent", "(IIIII)V");
+ sendMouseEventID = (*env)->GetMethodID(env, clazz, "sendMouseEvent", "(IIIIII)V");
sendKeyEventID = (*env)->GetMethodID(env, clazz, "sendKeyEvent", "(IIIC)V");
if (sizeChangedID == NULL ||
windowDestroyNotifyID == NULL ||
@@ -289,12 +289,12 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_kd_KDWindow_DispatchMessages
(*env)->CallVoidMethod(env, obj, sendMouseEventID,
(ptr->select==0) ? (jint) EVENT_MOUSE_RELEASED : (jint) EVENT_MOUSE_PRESSED,
(jint) 0,
- (jint) ptr->x, (jint) ptr->y, 1);
+ (jint) ptr->x, (jint) ptr->y, 1, 0);
} else {
DBG_PRINT( "event mouse: src: %d, s:%d, i:0x%X (%d,%d)\n", owner, ptr->select, ptr->index, ptr->x, ptr->y);
(*env)->CallVoidMethod(env, obj, sendMouseEventID, (jint) EVENT_MOUSE_MOVED,
0,
- (jint) ptr->x, (jint) ptr->y, 0);
+ (jint) ptr->x, (jint) ptr->y, 0, 0);
}
}
break;
diff --git a/src/newt/native/MouseEvent.h b/src/newt/native/MouseEvent.h
index 37157808b..e9c0476ef 100644
--- a/src/newt/native/MouseEvent.h
+++ b/src/newt/native/MouseEvent.h
@@ -8,6 +8,8 @@
#define EVENT_MOUSE_PRESSED 203
#define EVENT_MOUSE_RELEASED 204
#define EVENT_MOUSE_MOVED 205
+// can't find how to regenerate this file, adding manually
+#define EVENT_MOUSE_WHEEL_MOVED 207
// Generated by Java: EVENT_MOUSE_DRAGGED = 206;
#endif
diff --git a/src/newt/native/NewtMacWindow.m b/src/newt/native/NewtMacWindow.m
index 43f9b271e..e97d8b9ca 100644
--- a/src/newt/native/NewtMacWindow.m
+++ b/src/newt/native/NewtMacWindow.m
@@ -50,7 +50,7 @@ static JNIEnv* env = NULL;
+ (BOOL) initNatives: (JNIEnv*) env forClass: (jclass) clazz
{
- sendMouseEventID = (*env)->GetMethodID(env, clazz, "sendMouseEvent", "(IIIII)V");
+ sendMouseEventID = (*env)->GetMethodID(env, clazz, "sendMouseEvent", "(IIIIII)V");
sendKeyEventID = (*env)->GetMethodID(env, clazz, "sendKeyEvent", "(IIIC)V");
sizeChangedID = (*env)->GetMethodID(env, clazz, "sizeChanged", "(II)V");
positionChangedID = (*env)->GetMethodID(env, clazz, "positionChanged", "(II)V");
@@ -170,7 +170,7 @@ static jint mods2JavaMods(NSUInteger mods)
evType, javaMods,
(jint) location.x,
(jint) (contentRect.size.height - location.y),
- (jint) (1 + [event buttonNumber]));
+ (jint) (1 + [event buttonNumber]), 0);
}
- (void) mouseEntered: (NSEvent*) theEvent
diff --git a/src/newt/native/WindowsWindow.c b/src/newt/native/WindowsWindow.c
index 9d802b213..8a6617645 100755
--- a/src/newt/native/WindowsWindow.c
+++ b/src/newt/native/WindowsWindow.c
@@ -31,7 +31,7 @@
*
*/
-#include <windows.h>
+#include <Windows.h>
#include <tchar.h>
#include <stdlib.h>
// NOTE: it looks like SHFullScreen and/or aygshell.dll is not available on the APX 2500 any more
@@ -49,6 +49,22 @@ typedef int intptr_t;
#endif
#endif
+#ifndef WM_MOUSEWHEEL
+#define WM_MOUSEWHEEL 0x020A
+#endif //WM_MOUSEWHEEL
+
+#ifndef WHEEL_DELTA
+#define WHEEL_DELTA 120
+#endif //WHEEL_DELTA
+
+#ifndef WHEEL_PAGESCROLL
+#define WHEEL_PAGESCROLL (UINT_MAX)
+#endif //WHEEL_PAGESCROLL
+
+#ifndef GET_WHEEL_DELTA_WPARAM // defined for (_WIN32_WINNT >= 0x0500)
+#define GET_WHEEL_DELTA_WPARAM(wParam) ((short)HIWORD(wParam))
+#endif
+
#include "com_sun_javafx_newt_windows_WindowsWindow.h"
#include "EventListener.h"
@@ -124,7 +140,7 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
// Shouldn't happen
return DefWindowProc(wnd, message, wParam, lParam);
}
-
+
switch (message) {
case WM_CLOSE:
(*env)->CallVoidMethod(env, window, windowDestroyNotifyID);
@@ -172,44 +188,74 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
break;
case WM_LBUTTONDOWN:
- (*env)->CallVoidMethod(env, window, sendMouseEventID, (jint) EVENT_MOUSE_PRESSED,
- ConvertModifiers(wParam), (jint) LOWORD(lParam), (jint) HIWORD(lParam), (jint) 1);
+ (*env)->CallVoidMethod(env, window, sendMouseEventID,
+ (jint) EVENT_MOUSE_PRESSED,
+ ConvertModifiers(wParam),
+ (jint) LOWORD(lParam), (jint) HIWORD(lParam),
+ (jint) 1, (jint) 0);
useDefWindowProc = 1;
break;
case WM_LBUTTONUP:
- (*env)->CallVoidMethod(env, window, sendMouseEventID, (jint) EVENT_MOUSE_RELEASED,
- ConvertModifiers(wParam), (jint) LOWORD(lParam), (jint) HIWORD(lParam), (jint) 1);
+ (*env)->CallVoidMethod(env, window, sendMouseEventID,
+ (jint) EVENT_MOUSE_RELEASED,
+ ConvertModifiers(wParam),
+ (jint) LOWORD(lParam), (jint) HIWORD(lParam),
+ (jint) 1, (jint) 0);
useDefWindowProc = 1;
break;
case WM_MBUTTONDOWN:
- (*env)->CallVoidMethod(env, window, sendMouseEventID, (jint) EVENT_MOUSE_PRESSED,
- ConvertModifiers(wParam), (jint) LOWORD(lParam), (jint) HIWORD(lParam), (jint) 2);
+ (*env)->CallVoidMethod(env, window, sendMouseEventID,
+ (jint) EVENT_MOUSE_PRESSED,
+ ConvertModifiers(wParam),
+ (jint) LOWORD(lParam), (jint) HIWORD(lParam),
+ (jint) 2, (jint) 0);
useDefWindowProc = 1;
break;
case WM_MBUTTONUP:
- (*env)->CallVoidMethod(env, window, sendMouseEventID, (jint) EVENT_MOUSE_RELEASED,
- ConvertModifiers(wParam), (jint) LOWORD(lParam), (jint) HIWORD(lParam), (jint) 2);
+ (*env)->CallVoidMethod(env, window, sendMouseEventID,
+ (jint) EVENT_MOUSE_RELEASED,
+ ConvertModifiers(wParam),
+ (jint) LOWORD(lParam), (jint) HIWORD(lParam),
+ (jint) 2, (jint) 0);
useDefWindowProc = 1;
break;
case WM_RBUTTONDOWN:
- (*env)->CallVoidMethod(env, window, sendMouseEventID, (jint) EVENT_MOUSE_PRESSED,
- ConvertModifiers(wParam), (jint) LOWORD(lParam), (jint) HIWORD(lParam), (jint) 3);
+ (*env)->CallVoidMethod(env, window, sendMouseEventID,
+ (jint) EVENT_MOUSE_PRESSED,
+ ConvertModifiers(wParam),
+ (jint) LOWORD(lParam), (jint) HIWORD(lParam),
+ (jint) 3, (jint) 0);
useDefWindowProc = 1;
break;
case WM_RBUTTONUP:
- (*env)->CallVoidMethod(env, window, sendMouseEventID, (jint) EVENT_MOUSE_RELEASED,
- ConvertModifiers(wParam), (jint) LOWORD(lParam), (jint) HIWORD(lParam), (jint) 3);
+ (*env)->CallVoidMethod(env, window, sendMouseEventID,
+ (jint) EVENT_MOUSE_RELEASED,
+ ConvertModifiers(wParam),
+ (jint) LOWORD(lParam), (jint) HIWORD(lParam),
+ (jint) 3, (jint) 0);
useDefWindowProc = 1;
break;
case WM_MOUSEMOVE:
- (*env)->CallVoidMethod(env, window, sendMouseEventID, (jint) EVENT_MOUSE_MOVED,
- ConvertModifiers(wParam), (jint) LOWORD(lParam), (jint) HIWORD(lParam), (jint) 0);
+ (*env)->CallVoidMethod(env, window, sendMouseEventID,
+ (jint) EVENT_MOUSE_MOVED,
+ ConvertModifiers(wParam),
+ (jint) LOWORD(lParam), (jint) HIWORD(lParam),
+ (jint) 0, (jint) 0);
+ useDefWindowProc = 1;
+ break;
+
+ case WM_MOUSEWHEEL:
+ (*env)->CallVoidMethod(env, window, sendMouseEventID,
+ (jint) EVENT_MOUSE_WHEEL_MOVED,
+ ConvertModifiers(wParam),
+ (jint) LOWORD(lParam), (jint) HIWORD(lParam),
+ (jint) 0, (jint) GET_WHEEL_DELTA_WPARAM(wParam));
useDefWindowProc = 1;
break;
@@ -247,7 +293,7 @@ JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_initID
positionChangedID = (*env)->GetMethodID(env, clazz, "positionChanged", "(II)V");
windowDestroyNotifyID = (*env)->GetMethodID(env, clazz, "windowDestroyNotify", "()V");
windowDestroyedID = (*env)->GetMethodID(env, clazz, "windowDestroyed", "()V");
- sendMouseEventID = (*env)->GetMethodID(env, clazz, "sendMouseEvent", "(IIIII)V");
+ sendMouseEventID = (*env)->GetMethodID(env, clazz, "sendMouseEvent", "(IIIIII)V");
sendKeyEventID = (*env)->GetMethodID(env, clazz, "sendKeyEvent", "(IIIC)V");
if (sizeChangedID == NULL ||
positionChangedID == NULL ||