diff options
author | Sven de Marothy <sven@physto.se> | 2006-07-15 08:02:22 +0000 |
---|---|---|
committer | Sven de Marothy <sven@physto.se> | 2006-07-15 08:02:22 +0000 |
commit | bbf4a3c323efc72d1aa98631a6ceee6b23e8592a (patch) | |
tree | e3fdde62a6ae6bf3861ce74062bf3811db6be693 | |
parent | fba3c31e840bc2a3e25eca0b4933a7705c452e15 (diff) | |
download | classpath-bbf4a3c323efc72d1aa98631a6ceee6b23e8592a.tar.gz |
2006-07-15 Sven de Marothy <sven@physto.se>
* gnu/java/awt/peer/gtk/GtkMouseInfoPeer.java,
* java/awt/MouseInfo.java,
* java/awt/PointerInfo.java,
* java/awt/peer/MouseInfoPeer.java:
New files.
* java/awt/Image.java
(accelerationPriority): New field.
(setAccelerationPriority, getAccelerationPriority): New methods..
* include/gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.h,
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.c,
* gnu/java/awt/peer/gtk/GdkGraphicsEnvironment.java:
(getMouseCoordinates): New method.
* gnu/java/awt/peer/gtk/GtkFramePeer.java
(updateAlwaysOnTop): Remove stub overload.
* gnu/java/awt/ClasspathToolkit.java,
* gnu/java/awt/peer/gtk/GtkToolkit.java,
* include/gnu_java_awt_peer_gtk_GtkToolkit.h,
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c:
(getMouseInfoPeer): New method.
(getMouseNumberOfButtons): New method.
* gnu/java/awt/peer/gtk/GtkWindowPeer.java
* include/gnu_java_awt_peer_gtk_GtkWindowPeer.h
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c
(gtkWindowSetAlwaysOnTop): New method.
(updateAlwaysOnTop): Implement.
* java/awt/Toolkit.java,
(getMouseInfoPeer): New method.
* java/awt/Window.java
(alwaysOnTop): New field.
(isAlwaysOnTop, setAlwaysOnTop): New methods.
* java/awt/peer/WindowPeer.java: Doc fix.
-rw-r--r-- | ChangeLog | 42 | ||||
-rw-r--r-- | gnu/java/awt/ClasspathToolkit.java | 22 | ||||
-rw-r--r-- | gnu/java/awt/peer/gtk/GdkGraphicsEnvironment.java | 6 | ||||
-rw-r--r-- | gnu/java/awt/peer/gtk/GtkFramePeer.java | 6 | ||||
-rw-r--r-- | gnu/java/awt/peer/gtk/GtkMouseInfoPeer.java | 77 | ||||
-rw-r--r-- | gnu/java/awt/peer/gtk/GtkToolkit.java | 9 | ||||
-rw-r--r-- | gnu/java/awt/peer/gtk/GtkWindowPeer.java | 9 | ||||
-rw-r--r-- | include/gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.h | 1 | ||||
-rw-r--r-- | include/gnu_java_awt_peer_gtk_GtkToolkit.h | 1 | ||||
-rw-r--r-- | include/gnu_java_awt_peer_gtk_GtkWindowPeer.h | 1 | ||||
-rw-r--r-- | java/awt/Image.java | 38 | ||||
-rw-r--r-- | java/awt/MouseInfo.java | 95 | ||||
-rw-r--r-- | java/awt/PointerInfo.java | 84 | ||||
-rw-r--r-- | java/awt/Toolkit.java | 13 | ||||
-rw-r--r-- | java/awt/Window.java | 64 | ||||
-rw-r--r-- | java/awt/peer/MouseInfoPeer.java | 61 | ||||
-rw-r--r-- | java/awt/peer/WindowPeer.java | 5 | ||||
-rw-r--r-- | native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.c | 32 | ||||
-rw-r--r-- | native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c | 31 | ||||
-rw-r--r-- | native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c | 15 |
20 files changed, 592 insertions, 20 deletions
@@ -1,3 +1,45 @@ +2006-07-15 Sven de Marothy <sven@physto.se> + + * gnu/java/awt/peer/gtk/GtkMouseInfoPeer.java, + * java/awt/MouseInfo.java, + * java/awt/PointerInfo.java, + * java/awt/peer/MouseInfoPeer.java: + New files. + + * java/awt/Image.java + (accelerationPriority): New field. + (setAccelerationPriority, getAccelerationPriority): New methods.. + + * include/gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.h, + * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.c, + * gnu/java/awt/peer/gtk/GdkGraphicsEnvironment.java: + (getMouseCoordinates): New method. + + * gnu/java/awt/peer/gtk/GtkFramePeer.java + (updateAlwaysOnTop): Remove stub overload. + + * gnu/java/awt/ClasspathToolkit.java, + * gnu/java/awt/peer/gtk/GtkToolkit.java, + * include/gnu_java_awt_peer_gtk_GtkToolkit.h, + * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c: + (getMouseInfoPeer): New method. + (getMouseNumberOfButtons): New method. + + * gnu/java/awt/peer/gtk/GtkWindowPeer.java + * include/gnu_java_awt_peer_gtk_GtkWindowPeer.h + * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c + (gtkWindowSetAlwaysOnTop): New method. + (updateAlwaysOnTop): Implement. + + * java/awt/Toolkit.java, + (getMouseInfoPeer): New method. + + * java/awt/Window.java + (alwaysOnTop): New field. + (isAlwaysOnTop, setAlwaysOnTop): New methods. + + * java/awt/peer/WindowPeer.java: Doc fix. + 2006-07-14 Sven de Marothy <sven@physto.se> * java/awt/font/TextLayout.java: diff --git a/gnu/java/awt/ClasspathToolkit.java b/gnu/java/awt/ClasspathToolkit.java index 5f093b71b..968cc3b16 100644 --- a/gnu/java/awt/ClasspathToolkit.java +++ b/gnu/java/awt/ClasspathToolkit.java @@ -1,5 +1,5 @@ /* ClasspathToolkit.java -- Abstract superclass for Classpath toolkits. - Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -52,6 +52,7 @@ import java.awt.FontMetrics; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import java.awt.Image; +import java.awt.Point; import java.awt.Toolkit; import java.awt.font.FontRenderContext; import java.awt.image.ColorModel; @@ -188,6 +189,9 @@ public abstract class ClasspathToolkit */ public abstract Font createFont(int format, InputStream stream); + /** + * Creates a RobotPeer on a given GraphicsDevice. + */ public abstract RobotPeer createRobot (GraphicsDevice screen) throws AWTException; @@ -201,8 +205,24 @@ public abstract class ClasspathToolkit /** * Used to register ImageIO SPIs provided by the toolkit. + * + * Our default implementation does nothing. */ public void registerImageIOSpis(IIORegistry reg) { } + + /** + * Returns the number of mouse buttons. + * (used by java.awt.MouseInfo). + * + * This dummy implementation returns -1 (no mouse). + * toolkit implementors should overload this method if possible. + * @since 1.5 + */ + public int getMouseNumberOfButtons() + { + return -1; + } } + diff --git a/gnu/java/awt/peer/gtk/GdkGraphicsEnvironment.java b/gnu/java/awt/peer/gtk/GdkGraphicsEnvironment.java index 035819d1c..e095c7dad 100644 --- a/gnu/java/awt/peer/gtk/GdkGraphicsEnvironment.java +++ b/gnu/java/awt/peer/gtk/GdkGraphicsEnvironment.java @@ -134,5 +134,9 @@ public class GdkGraphicsEnvironment extends GraphicsEnvironment { throw new java.lang.UnsupportedOperationException (); } - + + /** + * Used by GtkMouseInfoPeer. + */ + native int[] getMouseCoordinates(); } diff --git a/gnu/java/awt/peer/gtk/GtkFramePeer.java b/gnu/java/awt/peer/gtk/GtkFramePeer.java index 6ec0b7298..faac6d71d 100644 --- a/gnu/java/awt/peer/gtk/GtkFramePeer.java +++ b/gnu/java/awt/peer/gtk/GtkFramePeer.java @@ -218,11 +218,7 @@ public class GtkFramePeer extends GtkWindowPeer // TODO Auto-generated method stub } - public void updateAlwaysOnTop() - { - // TODO Auto-generated method stub - - } + public boolean requestWindowFocus() { // TODO Auto-generated method stub diff --git a/gnu/java/awt/peer/gtk/GtkMouseInfoPeer.java b/gnu/java/awt/peer/gtk/GtkMouseInfoPeer.java new file mode 100644 index 000000000..7f54da6d3 --- /dev/null +++ b/gnu/java/awt/peer/gtk/GtkMouseInfoPeer.java @@ -0,0 +1,77 @@ +/* GtkToolkit.java -- Implements an AWT Toolkit using GTK for peers + Copyright (C) 2006 + Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.gtk; + +import java.awt.Point; +import java.awt.GraphicsDevice; +import java.awt.GraphicsEnvironment; +import java.awt.Window; +import java.awt.peer.MouseInfoPeer; + +/** + * The MouseInfoPeer is so small, I'm including it here. + */ +public class GtkMouseInfoPeer implements MouseInfoPeer +{ + private static GdkGraphicsEnvironment gde = new GdkGraphicsEnvironment(); + + public int fillPointWithCoords(Point p) + { + int[] coords = gde.getMouseCoordinates(); + p.x = coords[1]; + p.y = coords[2]; + return coords[0]; + } + + public boolean isWindowUnderMouse(Window w) + { + int[] coords = gde.getMouseCoordinates(); + GraphicsDevice[] gds = gde.getScreenDevices(); + + // Check if the screen of the Window and the cursor match + if( gds[ coords[0] ] != w.getGraphicsConfiguration().getDevice() ) + return false; + + // Return the bounds-check. + Point p = w.getLocationOnScreen(); + return (coords[1] >= p.x && coords[1] < p.x + w.getWidth() && + coords[2] >= p.y && coords[2] < p.y + w.getHeight() ); + } +} + diff --git a/gnu/java/awt/peer/gtk/GtkToolkit.java b/gnu/java/awt/peer/gtk/GtkToolkit.java index fdd7e09cb..62d497449 100644 --- a/gnu/java/awt/peer/gtk/GtkToolkit.java +++ b/gnu/java/awt/peer/gtk/GtkToolkit.java @@ -102,6 +102,7 @@ import java.awt.peer.LabelPeer; import java.awt.peer.ListPeer; import java.awt.peer.MenuBarPeer; import java.awt.peer.MenuItemPeer; +import java.awt.peer.MouseInfoPeer; import java.awt.peer.MenuPeer; import java.awt.peer.PanelPeer; import java.awt.peer.PopupMenuPeer; @@ -653,4 +654,12 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit } public static native void gtkMain(); + + protected MouseInfoPeer getMouseInfoPeer() + { + return new GtkMouseInfoPeer(); + } + + public native int getMouseNumberOfButtons(); + } // class GtkToolkit diff --git a/gnu/java/awt/peer/gtk/GtkWindowPeer.java b/gnu/java/awt/peer/gtk/GtkWindowPeer.java index d15beacb4..ca79a6d21 100644 --- a/gnu/java/awt/peer/gtk/GtkWindowPeer.java +++ b/gnu/java/awt/peer/gtk/GtkWindowPeer.java @@ -70,7 +70,7 @@ public class GtkWindowPeer extends GtkContainerPeer native void gtkWindowSetTitle (String title); native void gtkWindowSetResizable (boolean resizable); native void gtkWindowSetModal (boolean modal); - + native void gtkWindowSetAlwaysOnTop ( boolean alwaysOnTop ); native void realize (); /** Returns the cached width of the AWT window component. */ @@ -275,10 +275,13 @@ public class GtkWindowPeer extends GtkContainerPeer else q().postEvent (new WindowEvent ((Window) awtComponent, id, opposite)); } + + /** + * Update the always-on-top status of the native window. + */ public void updateAlwaysOnTop() { - // TODO Auto-generated method stub - + gtkWindowSetAlwaysOnTop( ((Window)awtComponent).isAlwaysOnTop() ); } protected void postExposeEvent (int x, int y, int width, int height) diff --git a/include/gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.h b/include/gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.h index 2a619c609..6177a6fb9 100644 --- a/include/gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.h +++ b/include/gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.h @@ -16,6 +16,7 @@ JNIEXPORT jobjectArray JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphicsEnvironment JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphicsEnvironment_nativeGetDefaultScreenDevice (JNIEnv *env, jobject); JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphicsEnvironment_nativeGetNumFontFamilies (JNIEnv *env, jobject); JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphicsEnvironment_nativeGetFontFamilies (JNIEnv *env, jobject, jobjectArray); +JNIEXPORT jintArray JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphicsEnvironment_getMouseCoordinates (JNIEnv *env, jobject); #ifdef __cplusplus } diff --git a/include/gnu_java_awt_peer_gtk_GtkToolkit.h b/include/gnu_java_awt_peer_gtk_GtkToolkit.h index ffeb39935..6cdcc622a 100644 --- a/include/gnu_java_awt_peer_gtk_GtkToolkit.h +++ b/include/gnu_java_awt_peer_gtk_GtkToolkit.h @@ -17,6 +17,7 @@ JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_gtk_GtkToolkit_getScreenResolution JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkToolkit_sync (JNIEnv *env, jobject); JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkToolkit_loadSystemColors (JNIEnv *env, jobject, jintArray); JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkToolkit_gtkMain (JNIEnv *env, jclass); +JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_gtk_GtkToolkit_getMouseNumberOfButtons (JNIEnv *env, jobject); #ifdef __cplusplus } diff --git a/include/gnu_java_awt_peer_gtk_GtkWindowPeer.h b/include/gnu_java_awt_peer_gtk_GtkWindowPeer.h index ad447f16a..10c47cc94 100644 --- a/include/gnu_java_awt_peer_gtk_GtkWindowPeer.h +++ b/include/gnu_java_awt_peer_gtk_GtkWindowPeer.h @@ -13,6 +13,7 @@ extern "C" JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkWindowPeer_gtkWindowSetTitle (JNIEnv *env, jobject, jstring); JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkWindowPeer_gtkWindowSetResizable (JNIEnv *env, jobject, jboolean); JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkWindowPeer_gtkWindowSetModal (JNIEnv *env, jobject, jboolean); +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkWindowPeer_gtkWindowSetAlwaysOnTop(JNIEnv *env, jobject, jboolean); JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkWindowPeer_realize (JNIEnv *env, jobject); JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkWindowPeer_create (JNIEnv *env, jobject, jint, jboolean, jobject); JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkWindowPeer_setVisibleNative (JNIEnv *env, jobject, jboolean); diff --git a/java/awt/Image.java b/java/awt/Image.java index 6ade302a1..8a1cc0f00 100644 --- a/java/awt/Image.java +++ b/java/awt/Image.java @@ -1,5 +1,5 @@ /* Image.java -- superclass for images - Copyright (C) 1999, 2002, 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -50,7 +50,7 @@ import java.awt.image.ReplicateScaleFilter; * * @author Aaron M. Renn (arenn@urbanophile.com) * @since 1.0 - * @status updated to 1.4 + * @status updated to 1.5 */ public abstract class Image { @@ -102,6 +102,12 @@ public abstract class Image public static final int SCALE_AREA_AVERAGING = 16; /** + * The acceleration priority of the image + * @since 1.5 + */ + protected float accelerationPriority; + + /** * A default constructor for subclasses. */ public Image() @@ -205,4 +211,32 @@ public abstract class Image * includes the actual image data. */ public abstract void flush(); + + /** + * Sets the acceleration priority of the image. + * This is a value from 0 (lowest) to 1 (highest), which may + * be used as a hint for image acceleration. + * E.g. higher priority images may be stored in video memory. + * @param priority - the priority + * @throws IllegalArgumentException if priority is not >= 0 and <= 1. + * + * @since 1.5 + */ + public void setAccelerationPriority(float priority) + { + if( priority < 0f || priority > 1f) + throw new IllegalArgumentException("Invalid priority value."); + accelerationPriority = priority; + } + + /** + * Returns the acceleration priority of the image. + * + * @see #setAccelerationPriority(float) + * @since 1.5 + */ + public float getAccelerationPriority() + { + return accelerationPriority; + } } // class Image diff --git a/java/awt/MouseInfo.java b/java/awt/MouseInfo.java new file mode 100644 index 000000000..957b6bccb --- /dev/null +++ b/java/awt/MouseInfo.java @@ -0,0 +1,95 @@ +/* MouseInfo.java -- utility methods for mice. + Copyright (C) 2006 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package java.awt; + +import gnu.java.awt.ClasspathToolkit; +import java.awt.peer.MouseInfoPeer; + +/** + * MouseInfo is a class containing utility functions for mouse information. + * + * @author Sven de Marothy + * @since 1.5 + */ +public class MouseInfo +{ + private static MouseInfoPeer peer; + + /** + * Returns a PointerInfo object containing information about the current + * location of the mouse pointer + * + * @throws HeadlessException if the current GraphicsEnvironment is headless. + * @return a PointerInfo object. + */ + public static PointerInfo getPointerInfo() throws HeadlessException + { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) + sm.checkPermission( new AWTPermission("watchMousePointer") ); + + if( GraphicsEnvironment.isHeadless() ) + throw new HeadlessException(); + + if( peer == null ) + peer = Toolkit.getDefaultToolkit().getMouseInfoPeer(); + + Point p = new Point(); + int screen = peer.fillPointWithCoords( p ); + + GraphicsDevice[] gds = GraphicsEnvironment.getLocalGraphicsEnvironment(). + getScreenDevices(); + + return new PointerInfo( gds[ screen ], p ); + } + + /** + * Returns the number of mouse buttons, or -1 if no mouse is connected. + * (mentioned in the 1.5 release notes) + * + * @throws HeadlessException if the current GraphicsEnvironment is headless. + * @return an integer number of buttons. + */ + public static int getNumberOfButtons() throws HeadlessException + { + if( GraphicsEnvironment.isHeadless() ) + throw new HeadlessException(); + return ((ClasspathToolkit)Toolkit.getDefaultToolkit()). + getMouseNumberOfButtons(); + } +} diff --git a/java/awt/PointerInfo.java b/java/awt/PointerInfo.java new file mode 100644 index 000000000..14d44a69b --- /dev/null +++ b/java/awt/PointerInfo.java @@ -0,0 +1,84 @@ +/* PointerInfo.java -- mouse pointer data + Copyright (C) 2006 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package java.awt; + +/** + * PointerInfo represents information about the mouse pointer, + * i.e. its GraphicsDevice and location. + * + * PointerInfo objects cannot be instantiated directly, but are + * retrieved from MouseInfo.getPointerInfo(). PointerInfo objects + * are immutable and will not be updated for future mouse motions. + * + * @since 1.5 + * @author Sven de Marothy + */ +public class PointerInfo +{ + private GraphicsDevice gd; + private Point p; + + /** + * Package-private constructor used by MouseInfo. + */ + PointerInfo( GraphicsDevice gd, Point p ) + { + this.gd = gd; + this.p = p; + } + + /** + * Returns the GraphicsDevice on which the mouse pointer was located + * + * @return a GraphicsDevice object. + */ + public GraphicsDevice getDevice() + { + return gd; + } + + /** + * Returns the coordinates of the mouse pointer. + * + * @return a Point object containing the pointer coordinates. + */ + public Point getLocation() + { + return p; + } +} diff --git a/java/awt/Toolkit.java b/java/awt/Toolkit.java index 4000cb53e..2842091c1 100644 --- a/java/awt/Toolkit.java +++ b/java/awt/Toolkit.java @@ -70,6 +70,7 @@ import java.awt.peer.ListPeer; import java.awt.peer.MenuBarPeer; import java.awt.peer.MenuItemPeer; import java.awt.peer.MenuPeer; +import java.awt.peer.MouseInfoPeer; import java.awt.peer.PanelPeer; import java.awt.peer.PopupMenuPeer; import java.awt.peer.ScrollPanePeer; @@ -332,6 +333,18 @@ public abstract class Toolkit protected abstract MenuItemPeer createMenuItem(MenuItem target); /** + * Returns a MouseInfoPeer. + * The default implementation of this method throws + * UnsupportedOperationException. + * + * Toolkit implementations should overload this if possible, however. + */ + protected MouseInfoPeer getMouseInfoPeer() + { + throw new UnsupportedOperationException("No mouse info peer."); + } + + /** * Creates a peer object for the specified <code>FileDialog</code>. * * @param target The <code>FileDialog</code> to create the peer for. diff --git a/java/awt/Window.java b/java/awt/Window.java index 8bc4715ae..d15cba0ac 100644 --- a/java/awt/Window.java +++ b/java/awt/Window.java @@ -80,6 +80,8 @@ public class Window extends Container implements Accessible private int state = 0; /** @since 1.4 */ private boolean focusableWindowState = true; + /** @since 1.5 */ + private boolean alwaysOnTop = false; // A list of other top-level windows owned by this window. private transient Vector ownedWindows = new Vector(); @@ -420,13 +422,17 @@ public class Window extends Container implements Accessible /** * Sends this window to the back so that all other windows display in * front of it. + * + * If the window is set to be always-on-top, this will remove its + * always-on-top status. */ public void toBack() { if (peer != null) { - WindowPeer wp = (WindowPeer) peer; - wp.toBack(); + if( alwaysOnTop ) + setAlwaysOnTop( false ); + ( (WindowPeer) peer ).toBack(); } } @@ -437,10 +443,7 @@ public class Window extends Container implements Accessible public void toFront() { if (peer != null) - { - WindowPeer wp = (WindowPeer) peer; - wp.toFront(); - } + ( (WindowPeer) peer ).toFront(); } /** @@ -1236,6 +1239,55 @@ public class Window extends Container implements Accessible } /** + * Returns whether the Windows is an always-on-top window, + * meaning whether the window can be obscured by other windows or not. + * + * @return <code>true</code> if the windows is always-on-top, + * <code>false</code> otherwise. + * @since 1.5 + */ + public final boolean isAlwaysOnTop() + { + return alwaysOnTop; + } + + /** + * Sets the always-on-top state of this window (if supported). + * + * Setting a window to always-on-top means it will not be obscured + * by any other windows (with the exception of other always-on-top + * windows). Not all platforms may support this. + * + * If an window's always-on-top status is changed to false, the window + * will remain at the front but not be anchored there. + * + * Calling toBack() on an always-on-top window will change its + * always-on-top status to false. + * + * @since 1.5 + */ + public final void setAlwaysOnTop(boolean alwaysOnTop) + { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) + sm.checkPermission( new AWTPermission("setWindowAlwaysOnTop") ); + + if( this.alwaysOnTop == alwaysOnTop ) + return; + + if( alwaysOnTop ) + toFront(); + + firePropertyChange("alwaysOnTop", this.alwaysOnTop, alwaysOnTop ); + this.alwaysOnTop = alwaysOnTop; + + if (peer != null) + ( (WindowPeer) peer).updateAlwaysOnTop(); + else + System.out.println("Null peer?!"); + } + + /** * Generate a unique name for this window. * * @return A unique name for this window. diff --git a/java/awt/peer/MouseInfoPeer.java b/java/awt/peer/MouseInfoPeer.java new file mode 100644 index 000000000..e9923a653 --- /dev/null +++ b/java/awt/peer/MouseInfoPeer.java @@ -0,0 +1,61 @@ +/* MouseInfoPeer.java -- peer interface for MouseInfo + Copyright (C) 2006 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package java.awt.peer; + +import java.awt.Point; +import java.awt.Window; + +/** + * MouseInfoPeer is the peer interface java.awt.MouseInfo. + * + * @author Sven de Marothy + * @since 1.5 + */ +public interface MouseInfoPeer +{ + /** + * Get the mouse pointer coordinates and store them in p (obviously non-null) + * returns the index of the current screen device of the mouse. + */ + public int fillPointWithCoords(Point p); + + /** + * Returns whether a given Window is under the mouse. + */ + public boolean isWindowUnderMouse(Window w); +} diff --git a/java/awt/peer/WindowPeer.java b/java/awt/peer/WindowPeer.java index 6c014de0b..00d103579 100644 --- a/java/awt/peer/WindowPeer.java +++ b/java/awt/peer/WindowPeer.java @@ -1,5 +1,5 @@ /* WindowPeer.java -- Interface for window peers - Copyright (C) 1999 Free Software Foundation, Inc. + Copyright (C) 1999, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -44,7 +44,8 @@ public interface WindowPeer extends ContainerPeer void toFront(); /** - * FIXME: unknown. + * Update the always-on-top status of the Window. + * * @since 1.5 */ void updateAlwaysOnTop(); diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.c index 89adcd1e5..6528ad43a 100644 --- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.c +++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.c @@ -241,3 +241,35 @@ Java_gnu_java_awt_peer_gtk_GdkGraphicsEnvironment_nativeGetDefaultScreenDevice return defaultDevice; } + +JNIEXPORT jintArray JNICALL +Java_gnu_java_awt_peer_gtk_GdkGraphicsEnvironment_getMouseCoordinates +(JNIEnv *env, jobject obj) +{ + jintArray retArray; + jint *values; + GdkDisplay *display; + gint x, y, screenIndex; + GdkScreen *screen; + + display = (GdkDisplay *) NSA_GET_DISPLAY_PTR(env, obj); + g_assert (display != NULL); + + gdk_threads_enter (); + + gdk_display_get_pointer (display, &screen, &x, &y, NULL); + screenIndex = gdk_screen_get_number( screen ); + + gdk_threads_leave (); + + retArray = (*env)->NewIntArray (env, 3); + values = (*env)->GetIntArrayElements (env, retArray, NULL); + + values[0] = screenIndex; + values[1] = x; + values[2] = y; + + (*env)->ReleaseIntArrayElements (env, retArray, values, 0); + + return retArray; +} diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c index c966f6331..82dd9b7ac 100644 --- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c +++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c @@ -387,6 +387,37 @@ Java_gnu_java_awt_peer_gtk_GtkToolkit_getScreenResolution return res; } +/** + * Report the number of mouse buttons + * Returns the number of buttons of the first mouse found, or -1 if no mouse + * seems to be connected. + */ +JNIEXPORT jint JNICALL +Java_gnu_java_awt_peer_gtk_GtkToolkit_getMouseNumberOfButtons + (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused))) +{ + jint res = -1; + GList *devices; + GdkDevice *d; + + gdk_threads_enter (); + + // FIXME: Why doesn't this return the correct number? + devices = gdk_devices_list(); + + while( res == -1 && devices != NULL ) + { + d = GDK_DEVICE( devices->data ); + if( d->source == GDK_SOURCE_MOUSE ) + res = d->num_keys; + devices = devices->next; + } + + gdk_threads_leave (); + + return res; +} + #define CONVERT(type, state) \ gdk_color_to_java_color (style->type[GTK_STATE_ ## state]) diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c index c3ecb00c8..851e2cf48 100644 --- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c +++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c @@ -1245,6 +1245,21 @@ Java_gnu_java_awt_peer_gtk_GtkWindowPeer_gtkWindowSetModal } JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkWindowPeer_gtkWindowSetAlwaysOnTop + (JNIEnv *env, jobject obj, jboolean alwaysOnTop) +{ + void *ptr; + + gdk_threads_enter (); + + ptr = NSA_GET_PTR (env, obj); + + gtk_window_set_keep_above (GTK_WINDOW (ptr), alwaysOnTop); + + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkWindowPeer_setVisibleNative (JNIEnv *env, jobject obj, jboolean visible) { |