summaryrefslogtreecommitdiff
path: root/libjava/classpath/java
diff options
context:
space:
mode:
authorfitzsim <fitzsim@138bc75d-0d04-0410-961f-82ee72b054a4>2007-12-05 18:04:44 +0000
committerfitzsim <fitzsim@138bc75d-0d04-0410-961f-82ee72b054a4>2007-12-05 18:04:44 +0000
commit1e35b63380704a5149fe5ecc74f77fc5f8d00d6f (patch)
tree18361aa2bba3ec82f967a259c1fd72c45c7abf3c /libjava/classpath/java
parent97f67e8325991858f090084f771494852fbf7f60 (diff)
downloadgcc-1e35b63380704a5149fe5ecc74f77fc5f8d00d6f.tar.gz
2007-12-05 Thomas Fitzsimmons <fitzsim@redhat.com>
* gnu/java/awt/peer/gtk/GdkGraphicsEnvironment.java, native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.c (isWindowUnderMouse): New method. * include/gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.h: Regenerate. * gnu/java/awt/peer/gtk/GtkComponentPeer.java (getLocationOnScreen): Move WindowPeer section to... * gnu/java/awt/peer/gtk/GtkWindowPeer.java (getLocationOnScreen): New method. * gnu/java/awt/peer/gtk/GtkMouseInfoPeer.java (isWindowUnderMouse): Implement. * java/awt/Component.java (getMousePosition): New method. (getMousePositionHelper): Likewise. (mouseOverComponent): Likewise. * java/awt/Container.java (getMousePosition): New method. (mouseOverComponent): Likewise. * classpath/lib/java/awt/Component.class, classpath/lib/java/awt/Component$BltBufferStrategy.class, classpath/lib/java/awt/Container$GfxPaintAllVisitor.class, classpath/lib/java/awt/Component$AccessibleAWTComponent $AccessibleAWTFocusHandler.class, classpath/lib/java/awt/Component$FlipBufferStrategy.class, classpath/lib/java/awt/Container$GfxVisitor.class, classpath/lib/java/awt/Component$AccessibleAWTComponent $AccessibleAWTComponentHandler.class, classpath/lib/java/awt/Container$AccessibleAWTContainer $AccessibleContainerHandler.class, classpath/lib/java/awt/Container.class, classpath/lib/java/awt/Container$AccessibleAWTContainer.class, classpath/lib/java/awt/Container$GfxPrintAllVisitor.class, classpath/lib/java/awt/Component$AccessibleAWTComponent.class, classpath/lib/java/awt/Container$GfxPaintVisitor.class, classpath/lib/java/awt/Container$GfxPrintVisitor.class, classpath/lib/java/awt/Component$HeavyweightInLightweightListener.class, classpath/lib/gnu/java/awt/peer/gtk/GtkComponentPeer.class, classpath/lib/gnu/java/awt/peer/gtk/GdkGraphicsEnvironment.class, classpath/lib/gnu/java/awt/peer/gtk/GtkMouseInfoPeer.class, classpath/lib/gnu/java/awt/peer/gtk/GtkWindowPeer.class, classpath/lib/gnu/java/awt/peer/gtk/GtkComponentPeer $RepaintTimerTask.class: Regenerate. 2007-12-05 Thomas Fitzsimmons <fitzsim@redhat.com> * gnu/java/awt/peer/gtk/GdkGraphicsEnvironment.h: Regenerate. * gnu/java/awt/peer/gtk/GtkWindowPeer.h: Likewise. * java/awt/Component.h: Likewise. * java/awt/Container.h: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@130627 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/classpath/java')
-rw-r--r--libjava/classpath/java/awt/Component.java56
-rw-r--r--libjava/classpath/java/awt/Container.java27
2 files changed, 83 insertions, 0 deletions
diff --git a/libjava/classpath/java/awt/Component.java b/libjava/classpath/java/awt/Component.java
index f8bed17618e..fe4fb9b8b0d 100644
--- a/libjava/classpath/java/awt/Component.java
+++ b/libjava/classpath/java/awt/Component.java
@@ -5834,6 +5834,62 @@ p * <li>the set of backward traversal keys
}
/**
+ * Returns the mouse pointer position relative to this Component's
+ * top-left corner.
+ *
+ * @return relative mouse pointer position
+ *
+ * @throws HeadlessException if in a headless environment
+ */
+ public Point getMousePosition() throws HeadlessException
+ {
+ return getMousePositionHelper(true);
+ }
+
+ Point getMousePositionHelper(boolean allowChildren) throws HeadlessException
+ {
+ if (GraphicsEnvironment.isHeadless())
+ throw new HeadlessException("can't get mouse position"
+ + " in headless environment");
+ if (!isShowing())
+ return null;
+
+ Component parent = this;
+ int windowRelativeXOffset = 0;
+ int windowRelativeYOffset = 0;
+ while (parent != null && !(parent instanceof Window))
+ {
+ windowRelativeXOffset += parent.getX();
+ windowRelativeYOffset += parent.getY();
+ parent = parent.getParent();
+ }
+ if (parent == null)
+ return null;
+
+ Window window = (Window) parent;
+ if (!Toolkit.getDefaultToolkit()
+ .getMouseInfoPeer().isWindowUnderMouse(window))
+ return null;
+
+ PointerInfo info = MouseInfo.getPointerInfo();
+ Point mouseLocation = info.getLocation();
+ Point windowLocation = window.getLocationOnScreen();
+
+ int x = mouseLocation.x - windowLocation.x;
+ int y = mouseLocation.y - windowLocation.y;
+
+ if (!mouseOverComponent(window.getComponentAt(x, y), allowChildren))
+ return null;
+
+ return new Point(x - windowRelativeXOffset, y - windowRelativeYOffset);
+ }
+
+ boolean mouseOverComponent(Component component, boolean allowChildren)
+ {
+ return component == this;
+ }
+
+ /**
* This method is used to implement transferFocus(). CHILD is the child
* making the request. This is overridden by Container; when called for an
* ordinary component there is no child and so we always return null.
diff --git a/libjava/classpath/java/awt/Container.java b/libjava/classpath/java/awt/Container.java
index 83d9f7b78c5..e7622f2e839 100644
--- a/libjava/classpath/java/awt/Container.java
+++ b/libjava/classpath/java/awt/Container.java
@@ -1098,6 +1098,33 @@ public class Container extends Component
}
/**
+ * Returns the mouse pointer position relative to this Container's
+ * top-left corner. If allowChildren is false, the mouse pointer
+ * must be directly over this container. If allowChildren is true,
+ * the mouse pointer may be over this container or any of its
+ * descendents.
+ *
+ * @param allowChildren true to allow descendents, false if pointer
+ * must be directly over Container.
+ *
+ * @return relative mouse pointer position
+ *
+ * @throws HeadlessException if in a headless environment
+ */
+ public Point getMousePosition(boolean allowChildren) throws HeadlessException
+ {
+ return super.getMousePositionHelper(allowChildren);
+ }
+
+ boolean mouseOverComponent(Component component, boolean allowChildren)
+ {
+ if (allowChildren)
+ return isAncestorOf(component);
+ else
+ return component == this;
+ }
+
+ /**
* Returns the component located at the specified point. This is done
* by checking whether or not a child component claims to contain this
* point. The first child component that does is returned. If no