From aea6bd2a7edfe115e31eac4d3009c9f6eaf1f7ab Mon Sep 17 00:00:00 2001 From: dav Date: Tue, 16 Sep 2008 12:17:02 +0400 Subject: [PATCH] 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons Summary: implementation of the more mouse buttons support Reviewed-by: art, dcherepanov --- make/sun/xawt/mapfile-vers | 1 + src/share/classes/java/awt/Robot.java | 122 +++- src/share/classes/java/awt/Toolkit.java | 35 +- .../java/awt/doc-files/DesktopProperties.html | 52 +- .../classes/java/awt/event/InputEvent.java | 106 +++- .../classes/java/awt/event/MouseEvent.java | 246 ++++++- .../classes/java/awt/peer/RobotPeer.java | 3 +- .../classes/sun/awt/HeadlessToolkit.java | 6 +- .../classes/sun/awt/X11/XBaseWindow.java | 25 +- .../classes/sun/awt/X11/XConstants.java | 36 +- .../sun/awt/X11/XDragSourceContextPeer.java | 4 +- .../classes/sun/awt/X11/XRobotPeer.java | 7 +- src/solaris/classes/sun/awt/X11/XToolkit.java | 13 +- src/solaris/classes/sun/awt/X11/XWindow.java | 87 +-- .../classes/sun/awt/X11/XWindowPeer.java | 12 +- src/solaris/native/sun/awt/awt_Robot.c | 86 ++- .../classes/sun/awt/windows/WRobotPeer.java | 4 +- .../classes/sun/awt/windows/WToolkit.java | 14 + .../native/sun/windows/awt_Component.cpp | 86 ++- .../native/sun/windows/awt_Component.h | 22 +- src/windows/native/sun/windows/awt_Robot.cpp | 63 +- src/windows/native/sun/windows/awt_Robot.h | 4 +- .../native/sun/windows/awt_Toolkit.cpp | 24 + src/windows/native/sun/windows/awt_Toolkit.h | 3 + .../native/sun/windows/awt_TrayIcon.cpp | 2 +- .../ExtraButtonDrag.java | 131 ++++ .../ModifierPermutation.java | 320 ++++++++++ .../MouseModifiersUnitTest_Extra.java | 490 ++++++++++++++ .../MouseModifiersUnitTest_Standard.java | 598 ++++++++++++++++++ .../AcceptExtraMouseButtons.java | 118 ++++ .../ManualInstructions.java | 305 +++++++++ .../RobotExtraButton/RobotExtraButton.java | 79 +++ .../ToolkitPropertyTest/SystemPropTest_1.java | 36 ++ .../ToolkitPropertyTest/SystemPropTest_2.java | 25 + .../ToolkitPropertyTest/SystemPropTest_3.java | 26 + .../ToolkitPropertyTest/SystemPropTest_4.java | 42 ++ .../ToolkitPropertyTest/SystemPropTest_5.java | 42 ++ .../ToolkitPropertyTest_Disable.java | 143 +++++ .../ToolkitPropertyTest_Enable.java | 120 ++++ .../ButtonArraysEquality.java | 83 +++ .../AcceptExtraButton/AcceptExtraButton.java | 53 ++ .../CTORRestrictions/CTORRestrictions.java | 89 +++ .../CTORRestrictions_Disable.java | 101 +++ .../CheckGetMaskForButton.java | 65 ++ 44 files changed, 3776 insertions(+), 153 deletions(-) create mode 100644 test/java/awt/Mouse/MouseModifiersUnitTest/ExtraButtonDrag.java create mode 100644 test/java/awt/Mouse/MouseModifiersUnitTest/ModifierPermutation.java create mode 100644 test/java/awt/Mouse/MouseModifiersUnitTest/MouseModifiersUnitTest_Extra.java create mode 100644 test/java/awt/Mouse/MouseModifiersUnitTest/MouseModifiersUnitTest_Standard.java create mode 100644 test/java/awt/Robot/AcceptExtraMouseButtons/AcceptExtraMouseButtons.java create mode 100644 test/java/awt/Robot/ManualInstructions/ManualInstructions.java create mode 100644 test/java/awt/Robot/RobotExtraButton/RobotExtraButton.java create mode 100644 test/java/awt/Toolkit/ToolkitPropertyTest/SystemPropTest_1.java create mode 100644 test/java/awt/Toolkit/ToolkitPropertyTest/SystemPropTest_2.java create mode 100644 test/java/awt/Toolkit/ToolkitPropertyTest/SystemPropTest_3.java create mode 100644 test/java/awt/Toolkit/ToolkitPropertyTest/SystemPropTest_4.java create mode 100644 test/java/awt/Toolkit/ToolkitPropertyTest/SystemPropTest_5.java create mode 100644 test/java/awt/Toolkit/ToolkitPropertyTest/ToolkitPropertyTest_Disable.java create mode 100644 test/java/awt/Toolkit/ToolkitPropertyTest/ToolkitPropertyTest_Enable.java create mode 100644 test/java/awt/event/InputEvent/ButtonArraysEquality/ButtonArraysEquality.java create mode 100644 test/java/awt/event/MouseEvent/AcceptExtraButton/AcceptExtraButton.java create mode 100644 test/java/awt/event/MouseEvent/CTORRestrictions/CTORRestrictions.java create mode 100644 test/java/awt/event/MouseEvent/CTORRestrictions/CTORRestrictions_Disable.java create mode 100644 test/java/awt/event/MouseEvent/CheckGetMaskForButton/CheckGetMaskForButton.java diff --git a/make/sun/xawt/mapfile-vers b/make/sun/xawt/mapfile-vers index 9e0b434b5..59c557787 100644 --- a/make/sun/xawt/mapfile-vers +++ b/make/sun/xawt/mapfile-vers @@ -151,6 +151,7 @@ SUNWprivate_1.1 { Java_sun_awt_X11_XRobotPeer_mouseReleaseImpl; Java_sun_awt_X11_XRobotPeer_mouseWheelImpl; Java_sun_awt_X11_XRobotPeer_setup; + Java_sun_awt_X11_XRobotPeer_getNumberOfButtonsImpl; Java_java_awt_Component_initIDs; Java_java_awt_Container_initIDs; Java_java_awt_Button_initIDs; diff --git a/src/share/classes/java/awt/Robot.java b/src/share/classes/java/awt/Robot.java index 2ce6a2686..94c71283c 100644 --- a/src/share/classes/java/awt/Robot.java +++ b/src/share/classes/java/awt/Robot.java @@ -70,10 +70,7 @@ public class Robot { private RobotPeer peer; private boolean isAutoWaitForIdle = false; private int autoDelay = 0; - private static final int LEGAL_BUTTON_MASK = - InputEvent.BUTTON1_MASK| - InputEvent.BUTTON2_MASK| - InputEvent.BUTTON3_MASK; + private static int LEGAL_BUTTON_MASK; // location of robot's GC, used in mouseMove(), getPixelColor() and captureScreenImage() private Point gdLoc; @@ -98,6 +95,19 @@ public class Robot { } init(GraphicsEnvironment.getLocalGraphicsEnvironment() .getDefaultScreenDevice()); + int tmpMask = 0; + if (Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled()){ + for (int i = 0; i < peer.getNumberOfButtons(); i++){ + tmpMask |= InputEvent.getMaskForButton(i+1); + } + } + tmpMask |= InputEvent.BUTTON1_MASK| + InputEvent.BUTTON2_MASK| + InputEvent.BUTTON3_MASK| + InputEvent.BUTTON1_DOWN_MASK| + InputEvent.BUTTON2_DOWN_MASK| + InputEvent.BUTTON3_DOWN_MASK; + LEGAL_BUTTON_MASK = tmpMask; } /** @@ -187,18 +197,55 @@ public class Robot { /** * Presses one or more mouse buttons. The mouse buttons should - * be released using the mouseRelease method. + * be released using the {@link #mouseRelease(int)} method. + * + * @param buttons the Button mask; a combination of one or more + * mouse button masks. + *

+ * It is allowed to use only a combination of valid values as a {@code buttons} parameter. + * A valid combination consists of {@code InputEvent.BUTTON1_DOWN_MASK}, + * {@code InputEvent.BUTTON2_DOWN_MASK}, {@code InputEvent.BUTTON3_DOWN_MASK} + * and values returned by the + * {@link InputEvent#getMaskForButton(int) InputEvent.getMaskForButton(button)} method. * - * @param buttons the Button mask; a combination of one or more - * of these flags: + * The valid combination also depends on a + * {@link Toolkit#areExtraMouseButtonsEnabled() Toolkit.areExtraMouseButtonsEnabled()} value as follows: + *

+ *

+ * The following standard button masks are also accepted: *

- * @throws IllegalArgumentException if the button mask is not a - * valid combination + * However, it is recommended to use {@code InputEvent.BUTTON1_DOWN_MASK}, + * {@code InputEvent.BUTTON2_DOWN_MASK}, {@code InputEvent.BUTTON3_DOWN_MASK} instead. + * Either extended {@code _DOWN_MASK} or old {@code _MASK} values + * should be used, but both those models should not be mixed. + * @throws IllegalArgumentException if the {@code buttons} mask contains the mask for extra mouse button + * and support for extended mouse buttons is {@link Toolkit#areExtraMouseButtonsEnabled() disabled} by Java + * @throws IllegalArgumentException if the {@code buttons} mask contains the mask for extra mouse button + * that does not exist on the mouse and support for extended mouse buttons is {@link Toolkit#areExtraMouseButtonsEnabled() enabled} by Java * @see #mouseRelease(int) + * @see InputEvent#getMaskForButton(int) + * @see Toolkit#areExtraMouseButtonsEnabled() + * @see java.awt.MouseInfo#getNumberOfButtons() + * @see java.awt.event.MouseEvent */ public synchronized void mousePress(int buttons) { checkButtonsArgument(buttons); @@ -209,16 +256,53 @@ public class Robot { /** * Releases one or more mouse buttons. * - * @param buttons the Button mask; a combination of one or more - * of these flags: + * @param buttons the Button mask; a combination of one or more + * mouse button masks. + *

+ * It is allowed to use only a combination of valid values as a {@code buttons} parameter. + * A valid combination consists of {@code InputEvent.BUTTON1_DOWN_MASK}, + * {@code InputEvent.BUTTON2_DOWN_MASK}, {@code InputEvent.BUTTON3_DOWN_MASK} + * and values returned by the + * {@link InputEvent#getMaskForButton(int) InputEvent.getMaskForButton(button)} method. + * + * The valid combination also depends on a + * {@link Toolkit#areExtraMouseButtonsEnabled() Toolkit.areExtraMouseButtonsEnabled()} value as follows: + *

+ *

+ * The following standard button masks are also accepted: *

+ * However, it is recommended to use {@code InputEvent.BUTTON1_DOWN_MASK}, + * {@code InputEvent.BUTTON2_DOWN_MASK}, {@code InputEvent.BUTTON3_DOWN_MASK} instead. + * Either extended {@code _DOWN_MASK} or old {@code _MASK} values + * should be used, but both those models should not be mixed. + * @throws IllegalArgumentException if the {@code buttons} mask contains the mask for extra mouse button + * and support for extended mouse buttons is {@link Toolkit#areExtraMouseButtonsEnabled() disabled} by Java + * @throws IllegalArgumentException if the {@code buttons} mask contains the mask for extra mouse button + * that does not exist on the mouse and support for extended mouse buttons is {@link Toolkit#areExtraMouseButtonsEnabled() enabled} by Java * @see #mousePress(int) - * @throws IllegalArgumentException if the button mask is not a valid - * combination + * @see InputEvent#getMaskForButton(int) + * @see Toolkit#areExtraMouseButtonsEnabled() + * @see java.awt.MouseInfo#getNumberOfButtons() + * @see java.awt.event.MouseEvent */ public synchronized void mouseRelease(int buttons) { checkButtonsArgument(buttons); diff --git a/src/share/classes/java/awt/Toolkit.java b/src/share/classes/java/awt/Toolkit.java index 5ac97013d..aaa6afdd5 100644 --- a/src/share/classes/java/awt/Toolkit.java +++ b/src/share/classes/java/awt/Toolkit.java @@ -1,5 +1,5 @@ /* - * Copyright 1995-2007 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1995-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -2550,4 +2550,37 @@ public abstract class Toolkit { } } } + + /** + * Reports whether events from extra mouse buttons are allowed to be processed and posted into + * {@code EventQueue}. + *
+ * To change the returned value it is necessary to set the {@code sun.awt.enableExtraMouseButtons} + * property before the {@code Toolkit} class initialization. This setting could be done on the application + * startup by the following command: + *
+    * java -Dsun.awt.enableExtraMouseButtons=false Application
+    * 
+ * Alternatively, the property could be set in the application by using the following code: + *
+    * System.setProperty("sun.awt.enableExtraMouseButtons", "true");
+    * 
+ * before the {@code Toolkit} class initialization. + * If not set by the time of the {@code Toolkit} class initialization, this property will be + * initialized with {@code true}. + * Changing this value after the {@code Toolkit} class initialization will have no effect. + *

+ * The current value could be queried by using the + * {@code System.getProperty("sun.awt.enableExtraMouseButtons")} method. + * @exception HeadlessException if GraphicsEnvironment.isHeadless() returns true + * @return {@code true} if events from extra mouse buttons are allowed to be processed and posted; + * {@code false} otherwise + * @see System#getProperty(String propertyName) + * @see System#setProperty(String propertyName, String value) + * @see java.awt.EventQueue + * @since 1.7 + */ + public boolean areExtraMouseButtonsEnabled() throws HeadlessException { + return Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled(); + } } diff --git a/src/share/classes/java/awt/doc-files/DesktopProperties.html b/src/share/classes/java/awt/doc-files/DesktopProperties.html index f699ba2fa..5f3afb374 100644 --- a/src/share/classes/java/awt/doc-files/DesktopProperties.html +++ b/src/share/classes/java/awt/doc-files/DesktopProperties.html @@ -1,5 +1,5 @@