summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorThomas Fitzsimmons <fitzsim@redhat.com>2007-11-27 22:06:57 +0000
committerThomas Fitzsimmons <fitzsim@redhat.com>2007-11-27 22:06:57 +0000
commit01332a3a7f7095b703bc492b9d47baf5e02cd292 (patch)
tree12c91e59d8adcdbfad5e5e2489f210b9949115ef /java
parentbe1b1415b49febe180ff2363e3edc7b4faf500d9 (diff)
downloadclasspath-01332a3a7f7095b703bc492b9d47baf5e02cd292.tar.gz
2007-11-27 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. * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c: Revert 2007-09-11 changes.
Diffstat (limited to 'java')
-rw-r--r--java/awt/Component.java56
-rw-r--r--java/awt/Container.java27
2 files changed, 83 insertions, 0 deletions
diff --git a/java/awt/Component.java b/java/awt/Component.java
index f8bed1761..fe4fb9b8b 100644
--- a/java/awt/Component.java
+++ b/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/java/awt/Container.java b/java/awt/Container.java
index 83d9f7b78..e7622f2e8 100644
--- a/java/awt/Container.java
+++ b/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