Fwd: Found and solved a bug on Cursor Management on Windows platforms (original) (raw)

Anthony Petrov anthony.petrov at oracle.com
Fri Apr 26 08:56:24 PDT 2013


Hi Morvan,

The IDC_HAND system cursor was introduced in Windows 2000. Java's HAND_CURSOR seems to be introduced way before Win2K has been released. Hence the need for a custom cursor back in the days. Clearly, this doesn't make any sense today. We should switch to using the system default cursor for this cursor type.

Would you like to prepare a patch for this issue, test it, and post on this mailing list for a review? I know that building JDK on Windows is not an easy task, but it can be accomplished nevertheless, and the new build system has made it much simpler than it was before. Please refer to this document

http://hg.openjdk.java.net/jdk8/build/raw-file/tip/README-builds.html

for build instructions.

-- best regards, Anthony

On 04/22/2013 08:32 PM, Morvan Le Mescam wrote:

Dear all,

When developping a Swing client, I face the following problem : When setting the hand cursor on Windows, I noticed that the default system cursor was not used. I analysed the problem and found the rrot cause. I also made a correction and tested it on Windows 7. This is my analyse : When reading Java source code, it is obvious that on Windows, Java does not use System resources. In the code (from jdk\src\windows\native\sun\windows\awtCursor.cpp ) bellow : AwtCursor * AwtCursor::CreateSystemCursor(jobject jCursor) { JNIEnv *env = (JNIEnv *)JNUGetEnv(jvm, JNIVERSION12); jint type = env->GetIntField(jCursor, AwtCursor::typeID); DASSERT(type != javaawtCursorCUSTOMCURSOR); LPCTSTR winCursor; switch (type) { case javaawtCursorDEFAULTCURSOR: default: winCursor = IDCARROW; break; case javaawtCursorCROSSHAIRCURSOR: winCursor = IDCCROSS; break; […] case javaawtCursorHANDCURSOR: winCursor = TEXT("HANDCURSOR"); break; case javaawtCursorMOVECURSOR: winCursor = IDCSIZEALL; break; } * HCURSOR hCursor = ::LoadCursor(NULL, winCursor);* if (hCursor == NULL) { /* Not a system cursor, check for resource. */ hCursor = ::LoadCursor(AwtToolkit::GetInstance().GetModuleHandle(), winCursor); } if (hCursor == NULL) { hCursor = ::LoadCursor(NULL, IDCARROW); DASSERT(hCursor != NULL); } AwtCursor *awtCursor = new AwtCursor(env, hCursor, jCursor); setPData(jCursor, ptrtojlong(awtCursor)); return awtCursor; } In the case of the HANDCURSOR (in red), Java will try to load the cursor from the system (in blue). If it fails (hCursor == NULL) then it will try to load the cursor from its own resource (in orange) : hCursor = ::LoadCursor(AwtToolkit::GetInstance().GetModuleHandle(), winCursor); In our case, if we check in the AWTToolkit module resources, in jdk\src\windows\native\sun\windows\awr.rc, we find the following content : #include "windows.h" // Need 2 defines so macro argument to XSTR will get expanded before quoting. #define XSTR(x) STR(x) #define STR(x) #x LANGUAGE LANGNEUTRAL, SUBLANGNEUTRAL HANDCURSOR CURSOR DISCARDABLE "hand.cur" AWTICON ICON DISCARDABLE "awt.ico" CHECKBITMAP BITMAP DISCARDABLE "check.bmp" And we find that java.exe embed its own hand cursor, in jdk\src\windows\native\sun\windows\hand.cur : The “famous” hand that it is displayed instead of our system cursor.

This is the correction : , I made the correction into the JRE source code : case javaawtCursorHANDCURSOR: /* MLM change winCursor = TEXT("HANDCURSOR"); */ winCursor = IDCHAND; break; I could compile and regenerate a JRE with this change : D:\Work\Current\openjdk\build\windows-amd64\bin>java -version openjdk version "1.7.0-u6-unofficial" OpenJDK Runtime Environment (build 1.7.0-u6-unofficial-b24) OpenJDK 64-Bit Server VM (build 21.0-b17, mixed mode) And this works ! If I change the hand cursor at System level, Java takes it into account. Last but not least question: Why did a Sun developper, one day : winCursor = TEXT("HANDCURSOR"); This seems so not consistent with other part of the code... So there is probably a good reason. Perhaps the hand cursor was not existant on Windows platform when this was done ? Regards Morvan



More information about the awt-dev mailing list