From efcbd94ea40dd4fb532707765535bd1af1639a03 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Fri, 30 May 2008 08:54:41 +0000 Subject: Completing com.sun.javafx.newt.* package, WIP, compile clean, but untested. - Input Event Handling: Mouse and Keyboard. - X11 port - Using the VisualID to construct the native window. git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JOGL_2_SANDBOX@1651 232f8b59-042b-4e1e-8c03-345bb8c30851 --- make/build.xml | 5 + make/gl-es1.cfg | 4 +- src/classes/com/sun/javafx/newt/EventListener.java | 39 +++ src/classes/com/sun/javafx/newt/InputEvent.java | 95 ++++++ src/classes/com/sun/javafx/newt/KeyEvent.java | 275 +++++++++++++++++ src/classes/com/sun/javafx/newt/KeyListener.java | 42 +++ src/classes/com/sun/javafx/newt/MouseEvent.java | 86 ++++++ src/classes/com/sun/javafx/newt/MouseListener.java | 46 +++ src/classes/com/sun/javafx/newt/Window.java | 149 ++++++++- .../com/sun/javafx/newt/windows/WindowsWindow.java | 64 +++- src/classes/com/sun/javafx/newt/x11/X11Window.java | 190 ++++++++++++ src/classes/com/sun/opengl/util/BufferUtil.java | 28 ++ src/native/jogl/KeyEvent.h | 10 + src/native/jogl/MouseEvent.h | 13 + src/native/jogl/WindowsWindow.c | 47 ++- src/native/jogl/X11Window.c | 333 +++++++++++++++++++++ 16 files changed, 1401 insertions(+), 25 deletions(-) create mode 100644 src/classes/com/sun/javafx/newt/EventListener.java create mode 100644 src/classes/com/sun/javafx/newt/InputEvent.java create mode 100644 src/classes/com/sun/javafx/newt/KeyEvent.java create mode 100644 src/classes/com/sun/javafx/newt/KeyListener.java create mode 100644 src/classes/com/sun/javafx/newt/MouseEvent.java create mode 100644 src/classes/com/sun/javafx/newt/MouseListener.java create mode 100755 src/classes/com/sun/javafx/newt/x11/X11Window.java create mode 100644 src/native/jogl/KeyEvent.h create mode 100644 src/native/jogl/MouseEvent.h create mode 100755 src/native/jogl/X11Window.c diff --git a/make/build.xml b/make/build.xml index 608e02e30..c758b69c4 100644 --- a/make/build.xml +++ b/make/build.xml @@ -892,6 +892,8 @@ + + @@ -1013,6 +1015,9 @@ + + + diff --git a/make/gl-es1.cfg b/make/gl-es1.cfg index 629d59330..19f33f3c4 100755 --- a/make/gl-es1.cfg +++ b/make/gl-es1.cfg @@ -179,8 +179,8 @@ CustomCCode #define GL_APICALL __declspec(dllimport) CustomCCode #include CustomCCode #include CustomCCode #include -CustomCCode /* Include missing function pointer typedef */ -CustomCCode typedef void (GL_APIENTRYP PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) (GLenum target, GLeglImageOES image); +# CustomCCode /* Include missing function pointer typedef */ +# CustomCCode typedef void (GL_APIENTRYP PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) (GLenum target, GLeglImageOES image); CustomCCode typedef int intptr_t; diff --git a/src/classes/com/sun/javafx/newt/EventListener.java b/src/classes/com/sun/javafx/newt/EventListener.java new file mode 100644 index 000000000..881d66b87 --- /dev/null +++ b/src/classes/com/sun/javafx/newt/EventListener.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.sun.javafx.newt; + +public interface EventListener +{ +} + diff --git a/src/classes/com/sun/javafx/newt/InputEvent.java b/src/classes/com/sun/javafx/newt/InputEvent.java new file mode 100644 index 000000000..e8644f953 --- /dev/null +++ b/src/classes/com/sun/javafx/newt/InputEvent.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.sun.javafx.newt; + +public abstract class InputEvent +{ + 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; + + protected InputEvent(boolean sysEvent, Window source, long when, int modifiers) { + this.consumed=false; + this.sysEvent=sysEvent; + this.source=source; + this.when=when; + this.modifiers=modifiers; + } + + protected boolean isSysEvent() { + return sysEvent; + } + + public void consume() { + consumed=true; + } + + public boolean isConsumed() { + return consumed; + } + public int getModifiers() { + return modifiers; + } + public long getWhen() { + return when; + } + public boolean isAltDown() { + return (modifiers&ALT_MASK)!=0; + } + public boolean isAltGraphDown() { + return (modifiers&ALT_GRAPH_MASK)!=0; + } + public boolean isControlDown() { + return (modifiers&CTRL_MASK)!=0; + } + public boolean isMetaDown() { + return (modifiers&META_MASK)!=0; + } + public boolean isShiftDown() { + return (modifiers&SHIFT_MASK)!=0; + } + + public String toString() { + return "InputEvent[sys:"+sysEvent+", source:"+source+", when:"+when+", modifiers:"+modifiers+"]"; + } + + private boolean sysEvent, consumed; + private Window source; + private int modifiers; + private long when; + +} + diff --git a/src/classes/com/sun/javafx/newt/KeyEvent.java b/src/classes/com/sun/javafx/newt/KeyEvent.java new file mode 100644 index 000000000..96df883df --- /dev/null +++ b/src/classes/com/sun/javafx/newt/KeyEvent.java @@ -0,0 +1,275 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.sun.javafx.newt; + +public class KeyEvent extends InputEvent +{ + protected KeyEvent(boolean sysEvent, int eventType, Window source, long when, int modifiers, int keyCode, char keyChar) { + super(sysEvent, source, when, modifiers); + this.eventType=eventType; + this.keyCode=keyCode; + this.keyChar=keyChar; + } + public KeyEvent(int eventType, Window source, long when, int modifiers, int keyCode, char keyChar) { + this(false, eventType, source, when, modifiers, keyCode, keyChar); + } + + public int getEventType() { + return eventType; + } + public char getKeyChar() { + return keyChar; + } + public int getKeyCode() { + return keyCode; + } + + public String toString() { + return "KeyEvent[code "+keyCode+", char "+keyChar+", "+super.toString(); + } + + public boolean isActionKey() { + switch (keyCode) { + case VK_HOME: + case VK_END: + case VK_PAGE_UP: + case VK_PAGE_DOWN: + case VK_UP: + case VK_DOWN: + case VK_LEFT: + case VK_RIGHT: + + case VK_F1: + case VK_F2: + case VK_F3: + case VK_F4: + case VK_F5: + case VK_F6: + case VK_F7: + case VK_F8: + case VK_F9: + case VK_F10: + case VK_F11: + case VK_F12: + case VK_F13: + case VK_F14: + case VK_F15: + case VK_F16: + case VK_F17: + case VK_F18: + case VK_F19: + case VK_F20: + case VK_F21: + case VK_F22: + case VK_F23: + case VK_F24: + case VK_PRINTSCREEN: + case VK_CAPS_LOCK: + case VK_PAUSE: + case VK_INSERT: + + case VK_HELP: + case VK_WINDOWS: + return true; + } + return false; + } + + private int eventType; + private int keyCode; + private char keyChar; + + public static final int EVENT_KEY_PRESSED = 1 << 0; + public static final int EVENT_KEY_RELEASED= 1 << 1; + public static final int EVENT_KEY_TYPED = 1 << 2; + + /* Virtual key codes. */ + + public static final int VK_ENTER = '\n'; + public static final int VK_BACK_SPACE = '\b'; + public static final int VK_TAB = '\t'; + public static final int VK_CANCEL = 0x03; + public static final int VK_CLEAR = 0x0C; + public static final int VK_SHIFT = 0x10; + public static final int VK_CONTROL = 0x11; + public static final int VK_ALT = 0x12; + public static final int VK_PAUSE = 0x13; + public static final int VK_CAPS_LOCK = 0x14; + public static final int VK_ESCAPE = 0x1B; + public static final int VK_SPACE = 0x20; + public static final int VK_PAGE_UP = 0x21; + public static final int VK_PAGE_DOWN = 0x22; + public static final int VK_END = 0x23; + public static final int VK_HOME = 0x24; + + /** + * Constant for the non-numpad left arrow key. + */ + public static final int VK_LEFT = 0x25; + + /** + * Constant for the non-numpad up arrow key. + */ + public static final int VK_UP = 0x26; + + /** + * Constant for the non-numpad right arrow key. + */ + public static final int VK_RIGHT = 0x27; + + /** + * Constant for the non-numpad down arrow key. + */ + public static final int VK_DOWN = 0x28; + + /** Constant for the F1 function key. */ + public static final int VK_F1 = 0x70; + + /** Constant for the F2 function key. */ + public static final int VK_F2 = 0x71; + + /** Constant for the F3 function key. */ + public static final int VK_F3 = 0x72; + + /** Constant for the F4 function key. */ + public static final int VK_F4 = 0x73; + + /** Constant for the F5 function key. */ + public static final int VK_F5 = 0x74; + + /** Constant for the F6 function key. */ + public static final int VK_F6 = 0x75; + + /** Constant for the F7 function key. */ + public static final int VK_F7 = 0x76; + + /** Constant for the F8 function key. */ + public static final int VK_F8 = 0x77; + + /** Constant for the F9 function key. */ + public static final int VK_F9 = 0x78; + + /** Constant for the F10 function key. */ + public static final int VK_F10 = 0x79; + + /** Constant for the F11 function key. */ + public static final int VK_F11 = 0x7A; + + /** Constant for the F12 function key. */ + public static final int VK_F12 = 0x7B; + + /** + * Constant for the F13 function key. + * @since 1.2 + */ + /* F13 - F24 are used on IBM 3270 keyboard; use random range for constants. */ + public static final int VK_F13 = 0xF000; + + /** + * Constant for the F14 function key. + * @since 1.2 + */ + public static final int VK_F14 = 0xF001; + + /** + * Constant for the F15 function key. + * @since 1.2 + */ + public static final int VK_F15 = 0xF002; + + /** + * Constant for the F16 function key. + * @since 1.2 + */ + public static final int VK_F16 = 0xF003; + + /** + * Constant for the F17 function key. + * @since 1.2 + */ + public static final int VK_F17 = 0xF004; + + /** + * Constant for the F18 function key. + * @since 1.2 + */ + public static final int VK_F18 = 0xF005; + + /** + * Constant for the F19 function key. + * @since 1.2 + */ + public static final int VK_F19 = 0xF006; + + /** + * Constant for the F20 function key. + * @since 1.2 + */ + public static final int VK_F20 = 0xF007; + + /** + * Constant for the F21 function key. + * @since 1.2 + */ + public static final int VK_F21 = 0xF008; + + /** + * Constant for the F22 function key. + * @since 1.2 + */ + public static final int VK_F22 = 0xF009; + + /** + * Constant for the F23 function key. + * @since 1.2 + */ + public static final int VK_F23 = 0xF00A; + + /** + * Constant for the F24 function key. + * @since 1.2 + */ + public static final int VK_F24 = 0xF00B; + + public static final int VK_PRINTSCREEN = 0x9A; + public static final int VK_INSERT = 0x9B; + public static final int VK_HELP = 0x9C; + public static final int VK_META = 0x9D; + + public static final int VK_BACK_QUOTE = 0xC0; + public static final int VK_QUOTE = 0xDE; + + public static final int VK_WINDOWS = 0x020C; +} + diff --git a/src/classes/com/sun/javafx/newt/KeyListener.java b/src/classes/com/sun/javafx/newt/KeyListener.java new file mode 100644 index 000000000..6f022c45a --- /dev/null +++ b/src/classes/com/sun/javafx/newt/KeyListener.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.sun.javafx.newt; + +public interface KeyListener extends EventListener +{ + public void keyPressed(KeyEvent e); + public void keyReleased(KeyEvent e); + public void keyTyped(KeyEvent e) ; +} + diff --git a/src/classes/com/sun/javafx/newt/MouseEvent.java b/src/classes/com/sun/javafx/newt/MouseEvent.java new file mode 100644 index 000000000..99026bd7b --- /dev/null +++ b/src/classes/com/sun/javafx/newt/MouseEvent.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.sun.javafx.newt; + +public class MouseEvent extends InputEvent +{ + public static final int BUTTON1 = 1; + public static final int BUTTON2 = 2; + public static final int BUTTON3 = 3; + + protected MouseEvent(boolean sysEvent, int eventType, Window source, long when, int modifiers, int x, int y, int clickCount, int button) + { + super(sysEvent, source, when, modifiers); + this.eventType=eventType; + this.x=x; + this.y=y; + this.clickCount=clickCount; + this.button=button; + } + 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 int getEventType() { + return eventType; + } + public int getButton() { + return button; + } + public int getClickCount() { + return clickCount; + } + public int getX() { + return x; + } + public int getY() { + return y; + } + + public String toString() { + return "MouseEvent["+x+"/"+y+", button "+button+", count "+clickCount+", "+super.toString(); + } + + private int eventType, x, y, clickCount, button; + + public static final int EVENT_MOUSE_CLICKED = 1 << 0; + public static final int EVENT_MOUSE_ENTERED = 1 << 1; + public static final int EVENT_MOUSE_EXITED = 1 << 2; + public static final int EVENT_MOUSE_PRESSED = 1 << 3; + public static final int EVENT_MOUSE_RELEASED = 1 << 4; + public static final int EVENT_MOUSE_MOVED = 1 << 5; + public static final int EVENT_MOUSE_DRAGGED = 1 << 6; + +} + diff --git a/src/classes/com/sun/javafx/newt/MouseListener.java b/src/classes/com/sun/javafx/newt/MouseListener.java new file mode 100644 index 000000000..f707979ba --- /dev/null +++ b/src/classes/com/sun/javafx/newt/MouseListener.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.sun.javafx.newt; + +public interface MouseListener extends EventListener +{ + public void mouseClicked(MouseEvent e); + public void mouseEntered(MouseEvent e); + public void mouseExited(MouseEvent e); + public void mousePressed(MouseEvent e); + public void mouseReleased(MouseEvent e); + public void mouseMoved(MouseEvent e); + public void mouseDragged(MouseEvent e); +} + diff --git a/src/classes/com/sun/javafx/newt/Window.java b/src/classes/com/sun/javafx/newt/Window.java index c9437a196..2bfcf1265 100755 --- a/src/classes/com/sun/javafx/newt/Window.java +++ b/src/classes/com/sun/javafx/newt/Window.java @@ -33,6 +33,9 @@ package com.sun.javafx.newt; +import java.util.ArrayList; +import java.util.Iterator; + public abstract class Window { /** OpenKODE window type */ public static final String KD = "KD"; @@ -47,7 +50,7 @@ public abstract class Window { public static final String MACOSX = "MacOSX"; /** Creates a Window of the default type for the current operating system. */ - public static Window create() { + public static Window create(long visualID) { String osName = System.getProperty("os.name"); String osNameLowerCase = osName.toLowerCase(); String windowType; @@ -58,7 +61,9 @@ public abstract class Window { } else { windowType = X11; } - return create(windowType); + Window window = create(windowType); + window.initNative(visualID); + return window; } @@ -82,13 +87,149 @@ public abstract class Window { } } - protected Window() { - } + protected abstract void initNative(long visualID); + public abstract void setVisible(boolean visible); public abstract void setSize(int width, int height); + public abstract void setPosition(int x, int y); + public abstract boolean isVisible(); public abstract int getWidth(); public abstract int getHeight(); + public abstract int getX(); + public abstract int getY(); public abstract boolean setFullscreen(boolean fullscreen); + public abstract boolean isFullscreen(); + public abstract int getDisplayWidth(); + public abstract int getDisplayHeight(); public abstract long getWindowHandle(); public abstract void pumpMessages(); + + // + // MouseListener Support + // + + public synchronized void addMouseListener(MouseListener l) { + if(l == null) { + return; + } + mouseListener.add(l); + } + + public synchronized void removeMouseListener(MouseListener l) { + if (l == null) { + return; + } + mouseListener.remove(l); + } + + public synchronized MouseListener[] getMouseListeners() { + return (MouseListener[]) mouseListener.toArray(); + } + + private ArrayList mouseListener = new ArrayList(); + private long lastMousePressed = 0; + private int lastMouseClickCount = 0; + public static final int ClickTimeout = 200; + + private void sendMouseEvent(int eventType, int modifiers, int x, int y, int button) { + long when = System.currentTimeMillis(); + MouseEvent eClicked = null; + MouseEvent e = null; + + if(MouseEvent.EVENT_MOUSE_PRESSED==eventType) { + if(when-lastMousePressedCallVoidMethod(env, window, keyDownID, (jlong) wParam); + (*env)->CallVoidMethod(env, obj, sendKeyEventID, (jint) EVENT_KEY_PRESSED, + (jint) 0, (jint) 0x28, (jchar) 0); useDefWindowProc = 1; break; case WM_KEYUP: - (*env)->CallVoidMethod(env, window, keyUpID, (jlong) wParam); + (*env)->CallVoidMethod(env, obj, sendKeyEventID, (jint) EVENT_KEY_PRESSED, + (jint) 0, (jint) 0x26, (jchar) 0); useDefWindowProc = 1; break; @@ -111,6 +117,11 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message, (*env)->CallVoidMethod(env, window, sizeChangedID, (jint) rc.right, (jint) rc.bottom); break; + /* FIXME: + case WM_MOUSE_LALA: + (*env)->CallVoidMethod(env, obj, sendMouseEventID, (jint) eventType, (jint) mod, + (jint) x, (jint) y, (jint) button); + */ default: useDefWindowProc = 1; } @@ -128,16 +139,18 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message, JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_initIDs (JNIEnv *env, jclass clazz) { - keyDownID = (*env)->GetMethodID(env, clazz, "keyDown", "(J)V"); - keyUpID = (*env)->GetMethodID(env, clazz, "keyUp", "(J)V"); sizeChangedID = (*env)->GetMethodID(env, clazz, "sizeChanged", "(II)V"); + positionChangedID = (*env)->GetMethodID(env, clazz, "positionChanged", "(II)V"); windowClosedID = (*env)->GetMethodID(env, clazz, "windowClosed", "()V"); windowDestroyedID = (*env)->GetMethodID(env, clazz, "windowDestroyed", "()V"); - if (keyDownID == NULL || - keyUpID == NULL || - sizeChangedID == NULL || + sendMouseEventID = (*env)->GetMethodID(env, clazz, "sendMouseEvent", "(IIIII)V"); + sendKeyEventID = (*env)->GetMethodID(env, clazz, "sendKeyEvent", "(IIIC)V"); + if (sizeChangedID == NULL || + positionChangedID == NULL || windowClosedID == NULL || - windowDestroyedID == NULL) { + windowDestroyedID == NULL || + sendMouseEventID == NULL || + sendKeyEventID == NULL) { return JNI_FALSE; } return JNI_TRUE; @@ -192,17 +205,20 @@ JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_RegisterW /* * Class: com_sun_javafx_newt_windows_WindowsWindow * Method: CreateWindow - * Signature: (Ljava/lang/String;II)J + * Signature: (Ljava/lang/String;JJIIII)J */ JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_CreateWindow - (JNIEnv *env, jobject obj, jstring windowClassName, jlong hInstance, jint defaultWidth, jint defaultHeight) + (JNIEnv *env, jobject obj, jstring windowClassName, jlong hInstance, jlong visualID, + jint jx, jint jy, jint defaultWidth, jint defaultHeight) { jchar* wndClassName = GetNullTerminatedStringChars(env, windowClassName); DWORD windowStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE; - int x, y; - int width, height; + int x=(int)x, y=(int)y; + int width=(int)defaultWidth, height=(int)defaultHeight; HWND window = NULL; +/** FIXME: why ? use setFullscreen() .. + * #ifdef UNDER_CE width = GetSystemMetrics(SM_CXSCREEN); height = GetSystemMetrics(SM_CYSCREEN); @@ -214,6 +230,9 @@ JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_CreateWin width = defaultWidth; height = defaultHeight; #endif + */ + (void) visualID; // FIXME: use the visualID .. + window = CreateWindowW(wndClassName, wndClassName, windowStyle, x, y, width, height, NULL, NULL, diff --git a/src/native/jogl/X11Window.c b/src/native/jogl/X11Window.c new file mode 100755 index 000000000..1c4200347 --- /dev/null +++ b/src/native/jogl/X11Window.c @@ -0,0 +1,333 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "com_sun_javafx_newt_x11_X11Window.h" + +#include "MouseEvent.h" +#include "KeyEvent.h" + +static jmethodID sizeChangedID = NULL; +static jmethodID positionChangedID = NULL; +static jmethodID windowClosedID = NULL; +static jmethodID windowDestroyedID = NULL; +static jmethodID windowCreatedID = NULL; +static jmethodID sendMouseEventID = NULL; +static jmethodID sendKeyEventID = NULL; + +// This is set by DispatchMessages, below, and cleared when it exits +static JNIEnv* env = NULL; + +#if 0 +static LRESULT CALLBACK wndProc(HWND wnd, UINT message, + WPARAM wParam, LPARAM lParam) +{ + RECT rc; + int useDefWindowProc = 0; + jobject window = NULL; + + window = (jobject) GetWindowLongPtr(wnd, GWLP_USERDATA); + if (window == NULL || env == NULL) { + // Shouldn't happen + return DefWindowProc(wnd, message, wParam, lParam); + } + + switch (message) { + case WM_CLOSE: + (*env)->CallVoidMethod(env, window, windowClosedID); + DestroyWindow(wnd); + break; + + case WM_DESTROY: + (*env)->CallVoidMethod(env, window, windowDestroyedID); + break; + + case WM_KEYDOWN: + (*env)->CallVoidMethod(env, window, keyDownID, (jlong) wParam); + useDefWindowProc = 1; + break; + + case WM_KEYUP: + (*env)->CallVoidMethod(env, window, keyUpID, (jlong) wParam); + useDefWindowProc = 1; + break; + + case WM_SIZE: + GetClientRect(wnd, &rc); + (*env)->CallVoidMethod(env, window, sizeChangedID, (jint) rc.right, (jint) rc.bottom); + break; + + default: + useDefWindowProc = 1; + } + + if (useDefWindowProc) + return DefWindowProc(wnd, message, wParam, lParam); + return 0; +} +#endif + +/* + * Class: com_sun_javafx_newt_x11_X11Window + * Method: initIDs + * Signature: ()Z + */ +JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_x11_X11Window_initIDs + (JNIEnv *env, jclass clazz) +{ + sizeChangedID = (*env)->GetMethodID(env, clazz, "sizeChanged", "(II)V"); + positionChangedID = (*env)->GetMethodID(env, clazz, "positionChanged", "(II)V"); + windowClosedID = (*env)->GetMethodID(env, clazz, "windowClosed", "()V"); + windowDestroyedID = (*env)->GetMethodID(env, clazz, "windowDestroyed", "()V"); + windowCreatedID = (*env)->GetMethodID(env, clazz, "windowCreated", "(JJJ)V"); + sendMouseEventID = (*env)->GetMethodID(env, clazz, "sendMouseEvent", "(IIIII)V"); + sendKeyEventID = (*env)->GetMethodID(env, clazz, "sendKeyEvent", "(IIIC)V"); + if (sizeChangedID == NULL || + positionChangedID == NULL || + windowClosedID == NULL || + windowDestroyedID == NULL || + windowCreatedID == NULL || + sendMouseEventID == NULL || + sendKeyEventID == NULL) { + return JNI_FALSE; + } + return JNI_TRUE; +} + +/* + * Class: com_sun_javafx_newt_x11_X11Window + * Method: CreateWindow + * Signature: (JIIII)J + */ +JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_x11_X11Window_CreateWindow + (JNIEnv *env, jobject obj, jlong visualID, + jint x, jint y, jint width, jint height) +{ + Display * dpy; + Screen * scrn; + Window windowParent = 0; + Window window = 0; + + XVisualInfo visualTemplate; + XVisualInfo *pVisualQuery = NULL; + XSetWindowAttributes xswa; + unsigned long attrMask; + + int n; + + dpy = XOpenDisplay(NULL); + if(dpy==NULL) { + fprintf(stderr, "could not open X display ..\n"); + return 0; + } + + memset(&visualTemplate, 0, sizeof(XVisualInfo)); + visualTemplate.visualid = (VisualID)visualID; + + pVisualQuery = XGetVisualInfo(dpy, VisualIDMask, &visualTemplate,&n); + if (pVisualQuery==NULL) + { + fprintf(stderr, "could not query XVisualInfo ..\n"); + return 0; + } + + scrn = ScreenOfDisplay(dpy, pVisualQuery->screen); + + windowParent = XRootWindowOfScreen(scrn); + + attrMask = (CWBackPixel | CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect); + memset(&xswa, 0, sizeof(xswa)); + xswa.override_redirect = True; + xswa.border_pixel = 0; + xswa.background_pixel = 0; + xswa.event_mask = ExposureMask | StructureNotifyMask | KeyPressMask | KeyReleaseMask; + xswa.colormap = XCreateColormap(dpy, + RootWindow(dpy, pVisualQuery->screen), + pVisualQuery->visual, + AllocNone); + + window = XCreateWindow(dpy, + windowParent, + x, y, + width, height, + 0, // border width + pVisualQuery->depth, + InputOutput, + pVisualQuery->visual, + attrMask, + &xswa); + XFree(pVisualQuery); + + (*env)->CallVoidMethod(env, obj, windowCreatedID, (jlong) (intptr_t) dpy, (jlong) (intptr_t) scrn, (jlong) window); + + return (jlong) window; +} + +/* + * Class: com_sun_javafx_newt_x11_X11Window + * Method: setVisible0 + * Signature: (JJZ)V + */ +JNIEXPORT void JNICALL Java_com_sun_javafx_newt_x11_X11Window_setVisible0 + (JNIEnv *env, jobject obj, jlong display, jlong window, jboolean visible) +{ + Display * dpy = (Display *) (intptr_t) display; + Window w = (Window)window; + if(visible==JNI_TRUE) { + XMapWindow(dpy, window); + + XSelectInput(dpy, window, ButtonPressMask|ButtonRelease|PointerMotionMask| + KeyPressMask|KeyReleaseMask); + } else { + XSelectInput(dpy, window, 0); + XUnmapWindow(dpy, window); + } +} + +/* + * Class: com_sun_javafx_newt_x11_X11Window + * Method: DispatchMessages + * Signature: (JJ)V + */ +JNIEXPORT void JNICALL Java_com_sun_javafx_newt_x11_X11Window_DispatchMessages + (JNIEnv *env, jobject obj, jlong display, jlong window) +{ + Display * dpy = (Display *) (intptr_t) display; + Window w = (Window)window; + + // Periodically take a break + while( XPending(dpy)>0 ) { + int eventType; + XEvent evt; + int i; + + XNextEvent(dpy, &evt); + + switch(evt.type) { + case ButtonPress: + (*env)->CallVoidMethod(env, obj, sendMouseEventID, (jint) EVENT_MOUSE_PRESSED, + (jint) evt.xbutton.state, + (jint) evt.xbutton.x, (jint) evt.xbutton.y, (jint) evt.xbutton.button); + break; + case ButtonRelease: + (*env)->CallVoidMethod(env, obj, sendMouseEventID, (jint) EVENT_MOUSE_RELEASED, + (jint) evt.xbutton.state, + (jint) evt.xbutton.x, (jint) evt.xbutton.y, (jint) evt.xbutton.button); + break; + case MotionNotify: + (*env)->CallVoidMethod(env, obj, sendMouseEventID, (jint) EVENT_MOUSE_MOVED, + (jint) evt.xmotion.state, + (jint) evt.xmotion.x, (jint) evt.xmotion.y, (jint) 0); + break; + case KeyPress: + i = evt.xkey.keycode; + (*env)->CallVoidMethod(env, obj, sendKeyEventID, (jint) EVENT_KEY_PRESSED, + (jint) evt.xkey.state, + (jint) i, (jchar) ( isascii(i)?i:0 ) ); + // evt.xkey + break; + case KeyRelease: + // evt.xkey + break; + case FocusIn: + // evt.xfocus + break; + case FocusOut: + // evt.xfocus + break; + } + } +} + +/* + * Class: com_sun_javafx_newt_x11_X11Window + * Method: setSize0 + * Signature: (JJII)V + */ +JNIEXPORT void JNICALL Java_com_sun_javafx_newt_x11_X11Window_setSize0 + (JNIEnv *env, jobject obj, jlong display, jlong window, jint width, jint height) +{ + Display * dpy = (Display *) (intptr_t) display; + Window w = (Window)window; + XResizeWindow(dpy, w, (unsigned)width, (unsigned)height); + (*env)->CallVoidMethod(env, obj, sizeChangedID, (jint) width, (jint) height); +} + +/* + * Class: com_sun_javafx_newt_x11_X11Window + * Method: setPosition0 + * Signature: (JJII)V + */ +JNIEXPORT void JNICALL Java_com_sun_javafx_newt_x11_X11Window_setPosition0 + (JNIEnv *env, jobject obj, jlong display, jlong window, jint x, jint y) +{ + Display * dpy = (Display *) (intptr_t) display; + Window w = (Window)window; + XMoveWindow(dpy, w, (unsigned)x, (unsigned)y); + // (*env)->CallVoidMethod(env, obj, positionChangedID, (jint) width, (jint) height); +} + +/* + * Class: com_sun_javafx_newt_x11_X11Window + * Method: getDisplayWidth0 + * Signature: (JJ)I + */ +JNIEXPORT jint JNICALL Java_com_sun_javafx_newt_x11_X11Window_getDisplayWidth0 + (JNIEnv *env, jobject obj, jlong display, jlong screen) +{ + Display * dpy = (Display *) (intptr_t) display; + Screen * scrn = (Screen *) (intptr_t) screen; + return (jint) XDisplayWidth( dpy, scrn); +} + +/* + * Class: com_sun_javafx_newt_x11_X11Window + * Method: getDisplayHeight0 + * Signature: (JJ)I + */ +JNIEXPORT jint JNICALL Java_com_sun_javafx_newt_x11_X11Window_getDisplayHeight0 + (JNIEnv *env, jobject obj, jlong display, jlong screen) +{ + Display * dpy = (Display *) (intptr_t) display; + Screen * scrn = (Screen *) (intptr_t) screen; + return (jint) XDisplayHeight( dpy, scrn); +} + + -- cgit v1.2.3