(original) (raw)
Thanks for this anwer.
I successfully rebuilt the JDK on Windows (see my first mail) so I think I can patch it but I don't really know how...
Regards
2013/4/26 Anthony Petrov <anthony.petrov@oracle.com>
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,In the code (from \*jdk\\src\\windows\\native\\sun\\windows\\awt\_Cursor.cpp\* )
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.
bellow :
AwtCursor \* AwtCursor::\*CreateSystemCursor\*(jobject jCursor)\*\[�\]\*
{
� � �JNIEnv \*env = (JNIEnv \*)JNU\_GetEnv(jvm, JNI\_VERSION\_1\_2);
� � �jint type = env->GetIntField(jCursor, AwtCursor::typeID);
� � �DASSERT(type != java\_awt\_Cursor\_CUSTOM\_CURSOR);
� � �LPCTSTR winCursor;
� � �switch (type) {
� � � �case java\_awt\_Cursor\_DEFAULT\_CURSOR:
� � � �default:
� � � � �winCursor = IDC\_ARROW;
� � � � �break;
� � � �case java\_awt\_Cursor\_CROSSHAIR\_CURSOR:
� � � � �winCursor = IDC\_CROSS;
� � � � �break;
\*case java\_awt\_Cursor\_HAND\_CURSOR:\*
\*winCursor = TEXT("HAND\_CURSOR");\*
\*break;\*
� � � �case java\_awt\_Cursor\_MOVE\_CURSOR:
� � � � �winCursor = IDC\_SIZEALL;
� � � � �break;
� � �}
\* � �HCURSOR hCursor = ::LoadCursor(NULL, winCursor);\*
� � �if (\*hCursor == NULL\*) {
� � � � �/\* Not a system cursor, check for resource. \*/\*hCursor = ::LoadCursor(AwtToolkit::GetInstance().GetModuleHandle(),\*
\*winCursor);\*In the case of the HAND\_CURSOR (\*in red\*), �Java will try to load the
� � �}
� � �if (hCursor == NULL) {
� � � � �hCursor = ::LoadCursor(NULL, IDC\_ARROW);
DASSERT(hCursor != NULL);
� � �}
� � �AwtCursor \*awtCursor = new AwtCursor(env, hCursor, jCursor);
� � �setPData(jCursor, ptr\_to\_jlong(awtCursor));
� � �return awtCursor;
}
If it fails (\*hCursor == NULL\*) then it will try to load the cursor from
cursor from the system (\*in blue\*).
\*hCursor = ::LoadCursor(AwtToolkit::GetInstance().GetModuleHandle(),\*
its own resource (\*in orange\*) :
\*winCursor);\*\*jdk\\src\\windows\\native\\sun\\windows\\awr.rc\*, we find the following content :
In our case, if we check in the AWTToolkit module resources, in
#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 LANG\_NEUTRAL, SUBLANG\_NEUTRAL
\*HAND\_CURSOR �CURSOR DISCARDABLE "hand.cur"\*
AWT\_ICON ICON � �DISCARDABLE "awt.ico"\*jdk\\src\\windows\\native\\sun\\windows\\hand.cur\* : The �famous� hand that
CHECK\_BITMAP BITMAP �DISCARDABLE "check.bmp"
And we find that java.exe embed its own hand cursor, in
it is displayed instead of our system cursor.
This is the correction :
, I made the correction into the JRE source code :
� � � �case java\_awt\_Cursor\_HAND\_CURSOR:
� � � � �/\* MLM change winCursor = TEXT("HAND\_CURSOR"); \*/
� � � � �winCursor = IDC\_HAND;
� � � � �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("HAND\_CURSOR");
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