6829267: Regression test java/awt/Toolkit/ToolkitPropertyTest/ToolkitPropertyTest_Enable.java fails in RHEL5
authordav
Fri, 01 Oct 2010 15:10:32 +0400
changeset 6642 9d6f6dbb16a4
parent 6641 4a5fb08cce1c
child 6643 38c5b164e76b
6829267: Regression test java/awt/Toolkit/ToolkitPropertyTest/ToolkitPropertyTest_Enable.java fails in RHEL5 Reviewed-by: art, anthony
jdk/src/solaris/classes/sun/awt/X11/XToolkit.java
jdk/src/windows/native/sun/windows/awt_DesktopProperties.cpp
jdk/src/windows/native/sun/windows/awt_Toolkit.cpp
jdk/src/windows/native/sun/windows/awt_Toolkit.h
jdk/test/java/awt/Toolkit/ToolkitPropertyTest/ToolkitPropertyTest_Enable.java
--- a/jdk/src/solaris/classes/sun/awt/X11/XToolkit.java	Thu Sep 30 21:06:53 2010 +0400
+++ b/jdk/src/solaris/classes/sun/awt/X11/XToolkit.java	Fri Oct 01 15:10:32 2010 +0400
@@ -1482,8 +1482,19 @@
         try {
             if (numberOfButtons == 0) {
                 numberOfButtons = getNumberOfButtonsImpl();
+                numberOfButtons = (numberOfButtons > MAX_BUTTONS_SUPPORTED)? MAX_BUTTONS_SUPPORTED : numberOfButtons;
+                //4th and 5th buttons are for wheel and shouldn't be reported as buttons.
+                //If we have more than 3 physical buttons and a wheel, we report N-2 buttons.
+                //If we have 3 physical buttons and a wheel, we report 3 buttons.
+                //If we have 1,2,3 physical buttons, we report it as is i.e. 1,2 or 3 respectively.
+                if (numberOfButtons >=5) {
+                    numberOfButtons -= 2;
+                } else if (numberOfButtons == 4 || numberOfButtons ==5){
+                    numberOfButtons = 3;
+                }
             }
-            return (numberOfButtons > MAX_BUTTONS_SUPPORTED)? MAX_BUTTONS_SUPPORTED : numberOfButtons;
+            //Assume don't have to re-query the number again and again.
+            return numberOfButtons;
         } finally {
             awtUnlock();
         }
--- a/jdk/src/windows/native/sun/windows/awt_DesktopProperties.cpp	Thu Sep 30 21:06:53 2010 +0400
+++ b/jdk/src/windows/native/sun/windows/awt_DesktopProperties.cpp	Fri Oct 01 15:10:32 2010 +0400
@@ -505,7 +505,8 @@
     SetIntegerProperty(TEXT("win.drag.width"), cxdrag);
     SetIntegerProperty(TEXT("win.drag.height"), cydrag);
     SetIntegerProperty(TEXT("DnD.gestureMotionThreshold"), max(cxdrag, cydrag)/2);
-    SetIntegerProperty(TEXT("awt.mouse.numButtons"), GetSystemMetrics(SM_CMOUSEBUTTONS));
+    SetIntegerProperty(TEXT("awt.mouse.numButtons"), AwtToolkit::GetNumberOfButtons());
+
     SetIntegerProperty(TEXT("awt.multiClickInterval"), GetDoubleClickTime());
 
     // BEGIN cross-platform properties
--- a/jdk/src/windows/native/sun/windows/awt_Toolkit.cpp	Thu Sep 30 21:06:53 2010 +0400
+++ b/jdk/src/windows/native/sun/windows/awt_Toolkit.cpp	Fri Oct 01 15:10:32 2010 +0400
@@ -133,6 +133,8 @@
 
 static LPCTSTR szAwtToolkitClassName = TEXT("SunAwtToolkit");
 
+static const int MOUSE_BUTTONS_WINDOWS_SUPPORTED = 5; //three standard buttons + XBUTTON1 + XBUTTON2.
+
 UINT AwtToolkit::GetMouseKeyState()
 {
     static BOOL mbSwapped = ::GetSystemMetrics(SM_SWAPBUTTON);
@@ -2310,5 +2312,9 @@
 
 JNIEXPORT jint JNICALL Java_sun_awt_windows_WToolkit_getNumberOfButtonsImpl
 (JNIEnv *, jobject self) {
-    return GetSystemMetrics(SM_CMOUSEBUTTONS);
+    return AwtToolkit::GetNumberOfButtons();
 }
+
+UINT AwtToolkit::GetNumberOfButtons() {
+    return MOUSE_BUTTONS_WINDOWS_SUPPORTED;
+}
--- a/jdk/src/windows/native/sun/windows/awt_Toolkit.h	Thu Sep 30 21:06:53 2010 +0400
+++ b/jdk/src/windows/native/sun/windows/awt_Toolkit.h	Fri Oct 01 15:10:32 2010 +0400
@@ -185,6 +185,7 @@
     BOOL IsDynamicLayoutActive();
     BOOL areExtraMouseButtonsEnabled();
     void setExtraMouseButtonsEnabled(BOOL enable);
+    static UINT GetNumberOfButtons();
 
     INLINE BOOL localPump() { return m_localPump; }
     INLINE BOOL VerifyComponents() { return FALSE; } // TODO: Use new DebugHelper class to set this flag
--- a/jdk/test/java/awt/Toolkit/ToolkitPropertyTest/ToolkitPropertyTest_Enable.java	Thu Sep 30 21:06:53 2010 +0400
+++ b/jdk/test/java/awt/Toolkit/ToolkitPropertyTest/ToolkitPropertyTest_Enable.java	Fri Oct 01 15:10:32 2010 +0400
@@ -90,7 +90,7 @@
         int [] buttonMasks = new int[MouseInfo.getNumberOfButtons()]; // = InputEvent.getButtonDownMasks();
         for (int i = 0; i < MouseInfo.getNumberOfButtons(); i++){
             buttonMasks[i] = InputEvent.getMaskForButton(i+1);
-            System.out.println("TEST: "+buttonMasks[i]);
+            System.out.println("TEST: buttonMasks["+ i +"] = " + buttonMasks[i]);
         }
 
         for (int i = 0; i < MouseInfo.getNumberOfButtons(); i++){